# Callback problem (newbie question!)

## Recommended Posts

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.

##### Share on other sites
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 :)

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628350
• Total Posts
2982211

• 10
• 9
• 24
• 11
• 9