Re: Wrapping C Libraries callback
- Posted by Icy_Viking Mar 18, 2017
- 1234 views
petelomax said...
Icy_Viking said...
FGAPI void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) );
This is the actual C code. I'm sure there is a special way you need to wrap the callback pointer in there.
That translates to (obviously untested, and somewhat based on the first hit I got from google being "void glutMouseWheelFunc(void(*)(int wheel, int direction, int x, int y) callback)")
-- library code: constant xglutMouseWheelFunc = define_c_proc(lib,"glutMouseWheelFunc",{C_POINTER}) procedure glutMouseWheelFunc(atom callback) c_proc(xglutMouseWheelFunc,{callback}) end procedure -- application code: function glutMouseWheelFunc_cb(integer wheel, integer direction, integer x, integer y) -- do what your app must do end function glutMouseWheelFunc(call_back(routine_id("glutMouseWheelFunc_cb")))
Or at least that would be my first stab.
I think that in C "void(* callback)()" and "void(*)() callback" are actually exactly the same thing, go figure.
Pete
That seems fairly easy enough, I thought a more complicated process would be needed.