Re: Gosu Wrapper
- Posted by ghaberek (admin) in July
- 486 views
Icy_Viking said...
I think the reason the input or drawing functions aren't working due to the way Gosu handle's callbacks. I'll have to look more into the callback functions.
GOSU_FFI_API void Gosu_Window_set_update(Gosu_Window* window, void function(void* data), void* data);
This function takes three parameters:
- Gosu_Window* window - a pointer to a Gosu_Window object
- void function(void* data) - a pointer to a function that accepts one parameter (this is our "callback")
- void* data - a generic pointer to any object (this is "user" object, a concept used by most callback-based systems)
If it helps, you can create alias constants to break up the sea of C_POINTER values everywhere. I find this helps weed out a lot of simple errors.
constant C_CALLBACK = C_POINTER -- pointer to a callback function constant C_PVOID = C_POINTER -- pointer to any object (void*) constant GOSU_WINDOW = C_POINTER -- pointer to a Gosu_Window object constant xGosu_Window_create = define_c_proc(gosu,"+Gosu_Window_create",{C_INT,C_INT,C_UINT,C_DOUBLE},GOSU_WINDOW) constant xGosu_Window_set_update = define_c_proc(gosu,"+Gosu_Window_set_update",{GOSU_WINDOW,C_CALLBACK,C_PVOID}) public function Gosu_Window_create(integer width, integer height, atom window_flags, atom update_interval) return c_func(xGosu_Window_create,{width,height,window_flags,update_interval}) end function public procedure Gosu_Window_set_update(atom window,object func,atom data) c_proc(xGosu_Window_set_update,{window,func,data}) end procedure
And it should come together something like this:
function update_callback(atom data) return 0 end function constant update_callback_id = routine_id("update_callback") constant update_callback_cb = call_back(update_callback) atom window = Gosu_Window_create(800, 450, 0, 1/60) Gosu_Window_set_update(window, update_callback_cb, NULL)
Disclaimer: I have not actually tried any of this to see if it works. I'm not sure how or if the callbacks are supposed to get knowledge about the window object.
-Greg