From: Mario S. <ma...@ru...> - 2016-07-22 08:28:10
|
Here's a silly question, Have you tried to implement the methods Peas::Activatable requires? EG: activate, deactivate, update_state, even if the methods aren't actually doing anything? EG: class Foo < GLib::Object type_register include Peas::Activatable def activate puts "Activate is here!" end def deactivate puts "Deactivate is here!" end def update_state puts "Update State is here!" end end $foo = Foo.new Then try on your C side: assert(PEAS_IS_ACTIVATABLE(foo_gobj)) Mario Steele Ruby Developer C# Developer Java Developer On Fri, Jul 22, 2016 at 2:07 AM, Thomas Martitz <ku...@ro...> wrote: > 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 > > > ------------------------------------------------------------------------------ > What NetFlow Analyzer can do for you? Monitors network bandwidth and > traffic > patterns at an interface-level. Reveals which users, apps, and protocols > are > consuming the most bandwidth. Provides multi-vendor support for NetFlow, > J-Flow, sFlow and other flows. Make informed decisions using capacity > planning > reports.http://sdm.link/zohodev2dev > _______________________________________________ > ruby-gnome2-devel-en mailing list > rub...@li... > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > |