I would like to know if there is any way for me to get the number of entries in a lua_getglobal
and get the name of each entry
I need to know why I need to use a loop to apply lua definitions in my C code:
example moon code:
Mytbl = {
var = {
active: true,
...
},
inv = {
active: true,
...
},
sts = {
active: true,
...
},
...
}
My C code:
void read_test(void) {
lua_State *L;
L = luaL_newstate();
luaL_openlibs(L);
if (luaL_loadfile(L, "test.lua") || lua_pcall(L, 0, 0, 0))
{
printf("Error 'test.lua'\n");
return;
}
lua_getglobal(L, "Mytbl");
for(int i = 1; i < GlobalEntry; i++) {
lua_getfield(L, lua_gettop(L), get_tablename);
lua_getfield(L, lua_gettop(L), "active");
p->active[i] = lua_toboolean(L, lua_gettop(L));
....
}
lua_close(L);
printf("Read complete.\n");
}
What is defined in the C code as GlobalEntry would be the function to get the amount of entries from lua_getglobal
And what is defined as get_tablename is the function that will get the name of the entries
Is there any lua function that allows you to do this?