Re: GLib/perl and GArray, GType




On Dec 11, 2008, at 9:47 AM, Wouter Verhelst wrote:

On Thu, Dec 11, 2008 at 12:31:09AM -0500, muppet wrote:

Now, it's fairly easy for you to create a function that knows how to
convert an array of whatever, and create a typemap for that. Then you
can use that all over the place in your own code.

Sounds like that could work. Having said that, I've not done much XS
code beyond this project, and since your code has generated all my
typemaps there (thanks, BTW), I wouldn't know where to start. Care to
give me a pointer? ;-)

Clue * clue_p = &a_big_clue;

[Okay, that was a horrible joke, i have to admit.]

The easiest would be to use typedef to create aliases for arrays and lists, so as to reflect their contents and give them unique symbols.

typedef GList * FooListOfGtkWidget

Then, in the file typemap, you can associate type mapping code with the typedef:

TYPEMAP
FooListOfWidgets        T_LIST_OF_WIDGET

INPUT
T_LIST_OF_WIDGET
        $var = av_to_glist_of_widget ($arg);

OUTPUT
T_LIST_OF_WIDGET
        $arg = av_from_glist_of_widget ($var);

You can also get really cute and try to infer the type name from the $var and $arg variables, as with T_GPERL_GENERIC_WRAPPER. There's more information on this in L<perlxstut>.


I had knocked together a patch that implements this, but working the
kinks out of value coercion in the unit test expanded to fill all my
available time for the evening, which was about half an hour. :- ( I'll
try to get you a working patch later this week.

That'd be great, thanks; and if you don't make it this week, there's no
rush -- I know what's going on, and this is (mostly) a hobby project
anyway.


I seem to be misunderstanding the GParamSpecGType docs when they talk about how is_a_type works when it's G_TYPE_NONE. So, the unit test is a bit incomplete, and i can't guarantee that this works as intended. Please try it out and let me know what you think. The patch is against SVN trunk HEAD, but should be easy to apply to a recent release -- not much has actually changed in these parts.

Attachment: GParamSpecGType.patch
Description: Binary data





--
zella (crying):  I want...
us:  What?
zella (still crying):  I want...  something!




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