[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] SWIG and c-callback with arguments
From: |
Bastian Müller |
Subject: |
[Chicken-users] SWIG and c-callback with arguments |
Date: |
Mon, 20 Aug 2007 00:56:21 +0200 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I'm currently trying to get an interface to the Open Dynamics Engine
with SWIG.
typedef void dNearCallback (void *data, dGeomID o1, dGeomID o2);
void dSpaceCollide (dSpaceID space, void *data, dNearCallback
*callback);
I saw that the glib egg is able to do callbacks using the following
code:
%{
static void
EGG_signal_handle ( gpointer *obj, gpointer closure_root )
{
C_callback(CHICKEN_gc_root_ref(closure_root), 0);
}
%}
%inline %{
gulong
EGG_g_signal_connect (gpointer obj, const gchar *type, C_word closure)
{
void *closure_root = CHICKEN_new_gc_root();
CHICKEN_gc_root_set(closure_root, closure);
return g_signal_connect(G_OBJECT(obj), type, G_CALLBACK
(EGG_signal_handle), closure_root);
}
%}
It seems to work fine, so I copied it and slightly modified it for ODE:
%{
static void
EGG_near_callback (void *closure_root, dGeomID o1, dGeomID o2) {
C_callback(CHICKEN_gc_root_ref(closure_root), 0);
}
%}
%inline %{
void
EGG_dSpaceCollide (dSpaceID space, C_word closure)
{
void *closure_root = CHICKEN_new_gc_root();
CHICKEN_gc_root_set(closure_root, closure);
return dSpaceCollide(space, closure_root, EGG_near_callback);
}
Then I noticed that glib's callback doesn't have any arguments, so
I changed it to:
C_callback(CHICKEN_gc_root_ref(closure_root), 2);
But even with that, the arguments I get in the actual scheme-callback
are wrong. I looked and searched for some documentation and stumbled
across C_save:
C_save(o1);
C_save(o2);
C_callback(CHICKEN_gc_root_ref(closure_root), 2);
Still, the code doesn't work with callback arguments.
It would be very cool if somebody with more knowledge
about scheme, chicken and swig could have a look at this.
Thanks in advance
- --
Bastian Müller - http://turbolent.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
iD8DBQFGyMqgUFTPKTPeTPURAoGbAJ9QZjttXjrXkNG1RC8MWq/8tRiC+QCeNzCD
oO5k6UkqTZRx26WxDS3KdO0=
=qolx
-----END PGP SIGNATURE-----
- [Chicken-users] SWIG and c-callback with arguments,
Bastian Müller <=