ryden Posted April 11, 2008 Share Posted April 11, 2008 When calling setTimer from a module, if you specify parameters to be sent to the callback and this parameter is a custom userdata it won't work. Works fine when you send plain data like, for example, a number. But if you push a userdata with this code this is what happens: static int test(lua_State* L) { pModuleManager->Printf("Timer called the callback\n"); return 0; } int myFunction(lua_State* L) { lua_getglobal(L, "setTimer"); lua_pushcfunction(L, test); lua_pushnumber(L, 1000); lua_pushnumber(L, 3); lua_newuserdata(L, sizeof(char)); /* Here we push the userdata */ lua_call(L, 4, 1); lua_pop(L, 1); } [07:33:15] ERROR: attempt to call a table value [07:33:16] ERROR: attempt to call a string value [07:33:17] ERROR: attempt to call a string value Now the same, but pushing a number: static int test(lua_State* L) { pModuleManager->Printf("Timer called the callback\n"); return 0; } int myFunction(lua_State* L) { lua_getglobal(L, "setTimer"); lua_pushcfunction(L, test); lua_pushnumber(L, 1000); lua_pushnumber(L, 3); lua_pushnumber(L, 16); /* Now instead of the userdata, we push a number */ lua_call(L, 4, 1); lua_pop(L, 1); } [07:36:49] Timer called the callback [07:36:50] Timer called the callback [07:36:51] Timer called the callback Link to comment
Recommended Posts