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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Robin Lee
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.

GIRepository::BaseInfo is the base class of GIRepository::CallableInfo, and the latter further has multiple derived classes.


-robin

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Torsten Schoenfeld-2
"Robin Lee" <[hidden email]>:
> 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.)

Might I ask what you are trying to accomplish with the information from GIRepository?

-Torsten
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Robin Lee


On Tue, Aug 8, 2017 at 3:18 PM, "Torsten Schönfeld" <[hidden email]> wrote:
"Robin Lee" <[hidden email]>:
> 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. 

-Torsten
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Loading...