gtk2-perl / allowing functions with callbacks to be wrapped
- From: Guillaume Cottenceau <gc mandrakesoft com>
- To: gtk-perl-list gnome org
- Subject: gtk2-perl / allowing functions with callbacks to be wrapped
- Date: 22 Nov 2002 12:21:18 +0100
Hi,
This morning I've worked on one of the still missing things in
gtk2-perl: we haven't wrapped any function that take a callback
as a parameter - the WhateverFunc typed parameters - for example
in the following function:
void gtk_tree_selection_selected_foreach(GtkTreeSelection *selection,
GtkTreeSelectionForeachFunc func,
gpointer data);
I've extended `genscripts/castmacros-autogen.pl' to be able to
automatically generate a marshal function for all the function
types. One just has to call it with one parameter indicating the
desired type name:
-=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=--
[gc obiwan ~/cvs/gtk2-perl] perl genscripts/castmacros-autogen.pl GtkTreeSelectionForeachFunc
/* auto generated marshal for GtkTreeSelectionForeachFunc (using genscripts/castmacros-autogen.pl
GtkTreeSelectionForeachFunc) */
void marshal_GtkTreeSelectionForeachFunc(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer
data)
{
struct callback_data * cb_data = data;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(gtk2_perl_new_object_from_pointer_nullok(model, "Gtk2::TreeModel")));
XPUSHs(sv_2mortal(gtk2_perl_new_object_from_pointer_nullok(path, "Gtk2::TreePath")));
XPUSHs(sv_2mortal(gtk2_perl_new_object_from_pointer_nullok(iter, "Gtk2::TreeIter")));
XPUSHs(cb_data->data);
PUTBACK;
perl_call_sv(cb_data->pl_func, G_DISCARD);
FREETMPS;
LEAVE;
}
-=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=--
Then, we copy that auto-generated code to the good .c file (in
our example, Gtk2/src/TreeSelection.c), and add the following
wrapper function:
-=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=--
void gtkperl_tree_selection_selected_foreach(SV* selection, SV* func, SV* data)
{
struct callback_data cb_data = { func, data };
gtk_tree_selection_selected_foreach(SvGtkTreeSelection(selection), marshal_GtkTreeSelectionForeachFunc,
&cb_data);
}
-=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=--
Pretty simple :).
There is an additional complexity for functions which install
callbacks to be called later on (cb_data needs to be allocated on
the heap, and some refcount manipulation needs to be performed),
but the story is similar (see the wrapper for
gtk_tree_selection_set_select_function if interested).
--
Guillaume Cottenceau - http://people.mandrakesoft.com/~gc/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]