Re: How to test object type and do casting in G::O::I

On Tue, Aug 8, 2017 at 3:18 PM, "Torsten Schönfeld" <torsten schoenfeld gmx de> wrote:
"Robin Lee" <robinlee sysu gmail com>:
> I am playing GIRepository with G::O::I.
> I get a GIRepository::BaseInfo object from gir get_info funtion.
> One question is how to test whether this object is a GIRepository::CallableInfo.
> And another question is how to cast this object to a GIRepository::CallableInfo.

For a normal GObject-based library, the C hierarchy would be mapped to Perl package hierarchy so that you could use $object->isa('Package') and so that casting wouldn't be necessary.

But GIRepository is not a GObject-based library, so you're basically in uncharted territory here Glib::Object::Introspection has not been written and tested with this application in mind.  But try calling ->get_type() on the GIRepository::BaseInfo object.  Once you know the type, try calling child class methods fully-qualified, for example:

  GIRepository::Struct::find_method ($base_info_which_is_struct_info, $name) 

Also, have a look at what 'perli11ndoc' presents for GIRepository to maybe get a better idea of what is possible.  (The calling syntax presented might, however, not be correct, because 'perli11ndoc' also assumes GObject semantics.)
Thank you! I found the calling method from perli11ndoc:

As for your example, the correct way is
GIRepository::struct_info_find_method ($base_info_which_is_struct_info, $name) 

That seems all 'methods' of the types derived from BaseInfo become namespace-level functions.

Might I ask what you are trying to accomplish with the information from GIRepository?
I am learning GI and want to try all the APIs of the GIR library. Using a scripting language is convenient for this task. 

gtk-perl-list mailing list
gtk-perl-list gnome org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]