|
From: Thomas M. <ku...@ro...> - 2016-07-22 06:07:39
|
Am 22.07.2016 um 04:13 schrieb Mario Steele:
> Hello Thomas,
>
> What your looking for to allow your Custom Ruby library to work with
> libpeas, and various other things, that require the GTYPE, is the
> ability to register it. To do this, I utilize this method of creating
> the class name:
>
> module MyModule
> class MyCustomClass < GLib::Object
> unless defined? MYCUSTOMCLASS_TYPE
> MYCUSTOMCLASS_TYPE = self.name.split(":").collect {|x| x.empty?
> ? nil : x}.compact.join("_")
> type_register(MYCUSTOMCLASS_TYPE)
> end
>
> # Proceed with defining my class, and required methods
> end
> end
>
> This class is a simple class, that inherits from GLib::Object, but can
> inherit from anything, as long as somewhere in it's ancestry,
> GLib::Object is a parent class for it. What the above does is:
>
> Converts MyModule::MyCustomClass to MyModule_MyCustomClass (Or
> MYMODULE_MYCUSTOMCLASS in C terms), and then calls
> GLib::Object#type_register() with the class name, which is defined by
> MYCUSTOMCLASS_TYPE. I include a defined? check, incase the file is
> loaded / required multiple times, or somehow re-loaded, the class
> doesn't accidentally get re-registered with GLib. Once you have done
> this, you should be able to associate the
> MyModule::MyCustomClass::MYCUSTOMCLASS_TYPE (Or just TYPE for short),
> with libpeas, and have libpeas utilize this.
>
> Hope this helps you out.
Thanks, this helped a bit. Based on your suggestion I found in the
examples that I should do:
class Foo < GLib::Object
type_register # this was missing
[…]
end
I can now successfully create a global $foo = Foo.new and in C:
void *(*rbg2gobj)(VALUE obj);
foo = rb_gv_get("$foo");
rbg2gobj = dlsym(NULL, "rbgobj_instance_from_ruby_object");
foo_gobj = rbg2gobj(foo);
assert(G_IS_OBJECT(foo_gobj));
However, I'm still unable to implement the Peas::Activatable interface,
due to the error message.
When I remove the specific check that throws this from the ruby-gnome2
code, then I can use the "include Peas::Activatable" statement. Then,
$foo.is_a?(Peas::Activatable) even returns true. BUT the following fails
(in C):
assert(PEAS_IS_ACTIVATABLE(foo_gobj));
Doing the "include Peas::Activatable" before or after the type_register
call doesn't seem to matter.
Best regards
|