#1 Lua:
local test = Test();
#2 C:
//creating "lua's test"
luaL_newmetatable(L, "someTable");
lua_userdata *userData = (lua_userdata *)lua_newuserdata(L, sizeof(lua_userdata));
luaL_getmetatable(L, "someTable");
lua_setmetatable(L, -2);
#3 Lua:
function test.newMethod()
end
#4 C:
//this part is not executed from Lua
//what i have to have here from #2 to call "test.newMethod" and how to call it?
//if userdata would be on stack i guess i could:
luaL_getmetafield (L, 1, "newMethod");
lua_call(L, 0, 0);
//but because this part is not executed by Lua call its not on stack.
Edited:
will try to explain simpler in pseudo code:
Lua:
local test = Object();
C:
int Object(){
...
somePointer = luaL_newmetatable(...); //how to get this "somePointer"? maybe luaL_ref?
push ...
}
Lua: makes new method
function test.newMethod()
...
end
In C some event (lets say timer) triggers C method
void triggeredCMethod(){
//here i need to call test.newMethod
//if i would have here 'somePointer' and could push it to Lua stack i could find and call newMethod
}
so question is: how in C store pointer to some Lua object (hope i need that), get Lua object by that pointer and call method in it
I'm assuming you want to be able to call dynamically added functions. This code should explain it relatively simply. Note I don't do much error checking and make a few assumptions, don't copy paste this as a solution.
Check that, I think that's what you're after.