first sorry for the weired title:( I am using lua as a scripting languge for my game and I have a problem: I am creating lua table instances and storing them in indices "ref_idx " like this:
lua_newtable(L);
lua_getglobal(L, "TestTable"); // create instance of table "TestTable"
lua_pcall(L, 0, 1, 0);
ref_idx = luaL_ref(L, LUA_REGISTRYINDEX);
and when i want to call a method of one of them I use:
lua_rawgeti(L, LUA_REGISTRYINDEX, ref_idx);
lua_getfield(L, -1, "testMethod");
lua_pushvalue(L, -2);
lua_pcall(L, 1, 0, 0));
lua_pop(L, 0);
when I am done with the reference:
luaL_unref(L, LUA_REGISTRYINDEX, ref_idx);
Every thing works fine, the problem is I want to use these reference in lua directly something like:
function onUpdate()
local ref = GetReferenceFromC++() -- returns ref_idx
ref:testMethod()
end
Any help or a way to do it? (sorry for my english, I am working on it)
I used debug.getregistry()[ref]:testMethod()
and it works, Thank you @EgorSkriptunoff for your quick response.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.