Callback problem (newbie question!)

Started by
0 comments, last by S41NT 18 years, 6 months ago
Hi! Our team is developing a game engine and we will use callbacks to let script writers deal with collisions and other stuff detected by the engine. So I write a test function which at some point goes like this:

// function to be called
lua_getglobal(CLuaScript::L, l_pcFunctionName);

void *test = (void *)&(a_callback.report);
//pushing collision report onto the stack
lua_pushlightuserdata(CLuaScript::L, &test);

// do the call (0 arguments, 0 result)
lua_pcall(CLuaScript::L, 1, 0, 0);
At the script, theres a function with the specified name and it is called. But I can't get the report back. Then I tried casting IN THE SCRIPT to the correct type: tolua.cast(variable, "Report"); And everything works. I don't want to cast inside the script. How can I make the callback specifying the type of the argument? Thanks very much.
Advertisement
If I understand things correctly, I should assign a metatable to the userdata pushed onto the stack. I tried, but without sucess. So that means I'm still looking for help :)

This topic is closed to new replies.

Advertisement