Pass function pointer with varying arguments?
BlitzMax Forums/BlitzMax Programming/Pass function pointer with varying arguments?
| ||
I am working on a wrapper for a C library (LibGTK and LibGlade), and almost everything is alive. The library (a GUI library) uses callback functions as Signal Handlers, so for example when a button is pressed a signal is sent out, then its handler is linked to my callback function which does whatever I want it to do. That particular function is set up like this: Function glade_xml_signal_connect(document:Byte Ptr , handlername$z , func(widget:Byte Ptr , user_data:Byte Ptr) )...which works for most situations. However, (and this is completely beyond the pale), certain signals want different callback functions that take different arguments. For example, a GTKDialog's Response signal wants a callback function like this: user_function (GtkDialog *dialog, gint arg1, gpointer user_data)That is one argument more than most other callbacks! This causes a crash :( From a quick glance, I gather that the real function will really take any function pointer, as the arguments for that function aren't figured out until the assigned callback is called from a known signal (and that signal knows what kind of functions it wants). If it is the wrong kind of function, the program crashes. I could go through these odd exceptions and create a new signal connect function for each, or I could create a special signal handler for the Response signal, but those two seem like rather unfavourable solutions compared to "just" taking a function pointer that could have any number of arguments. |
| ||
Hm... Duh! (Sorry, should have tried a few more things before I posted). Extern Function glade_xml_signal_connect(document:Byte Ptr , handlername$z , func:Byte Ptr ) End ExternIs that likely to bite me down the line, or should it work fine? |
| ||
That will work fine. |