-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let Crystal user objects be created from g_gobject_new calls.
This is a breaking change, since it now requires all GObject subclasses to have a constructor without arguments. What changed: There are 2 thread local variables to inform if the object is being created in C land or Crystal land, we store the objects instance pointers there. When the object is created in C land, the Crystal instance is created on GObject instance_init method. When the object is created in Crystal land, the GObject instance_init method creates no Crystal instance. This also fixes the use case of tryign to use a Crystal defined GObject property before the Wrapper gets fully initialized. Fixes hugopl/gtk4.cr#69
- Loading branch information
Showing
7 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require "./spec_helper" | ||
|
||
private class UserObj < GObject::Object | ||
@[GObject::Property] | ||
property crystal_prop = "" | ||
getter crystal_attr : Int32 = 42 | ||
|
||
def initialize(@hey = "") | ||
super() | ||
end | ||
end | ||
|
||
describe "Crystal GObjects" do | ||
it "can born in C land" do | ||
puts "\n\n\n" | ||
ptr = LibGObject.g_object_new(UserObj.g_type, "crystal_prop", "value", Pointer(Void).null) | ||
user_obj = UserObj.new(ptr, :none) | ||
user_obj.crystal_prop.should eq("value") | ||
user_obj.crystal_attr.should eq(42) | ||
end | ||
|
||
it "can born in Crystal land" do | ||
puts "\n\n\n" | ||
user_obj = UserObj.new | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -279,3 +279,4 @@ types: | |
execute_callback: | ||
- g_signal_emitv | ||
- g_closure_invoke | ||
- g_object_newv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters