Hi,

  My suggestion is to create a pool of callbacks in C, that can be
referenced com Crystal. Don't know Crystal, but I'm assuming it can call C
functions.

  The control callbacks are registered with a description of its signature.
So whenever a callback is set in Crystal, you look for its name in the IUP
class (using internal IUP functions) and you get a description of its
signature, then retrieve a callback in C from your pool with that signature
and set it using IupSetCallback. When the callback in C is called, it will
repass its parameters to Crystal, calling the Crystal function that was set
originally. In Lua we do a very similar approach.

Best,
Scuri


Em seg., 11 de mai. de 2020 às 10:23, Ben Hansen <aeta@watashi-no.space>
escreveu:

> Hello
>
> I've been trying to create an IUP language binding for the Crystal
> language[1]. What I've got so far works fine, however, I haven't been
> able to bind `IupSetCallback` or `IupSetCallbacks` in an idiomatic way.
>
> I created a post on the Crystal forums about this[2], the summary is
> that: to have this work in a "nice" way, either the original C function
> needs to have a `void* data`-type argument that can be used[3], or I
> create a singleton class which stores all the (Crystal) callbacks and
> looks up the appropriate one when writing the (C) callback.
>
> While the first option doesn't seem possible (considering it'd
> probably be a breaking change with no benefit), is there some way in
> IUP that I can use to be notified when the set callback isn't needed
> anymore as the control/dialog isn't either?
>
> Thanks,
> Ben
>
> [1]: https://crystal-lang.org
>
> [2]: https://forum.crystal-lang.org/t/c-binding-non-void-callback/2079
>
> [3]: similar to `gpointer data` for `g_signal_connect_data()` in Gtk
>
> https://developer.gnome.org/gobject/stable/gobject-Signals.html#g-signal-connect-data
>
>
> _______________________________________________
> Iup-users mailing list
> Iup-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/iup-users
>
_______________________________________________
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to