I'm starting in the world of lua currently I'm creating table readings using C code
I have a table that looks like this:
Consume =
{
Consume_first = {
Value = 100
Request = 200
},
Require_var = {
Enable= true
Name = "Am"
}
}
I would like to know some information
Consume is defined as lua_getglobal(L, "Consume");
Value, Request, Enable and Name would the lua_getfield function be used?
Example:
lua_getfield(L, 1, "Value")
And in Consume_first and Require_var what should I use to define them?
My code:
void read_table(void) {
lua_State *L;
L = luaL_newstate();
luaL_openlibs(L);
if (luaL_loadfile(L, "table.lua") || lua_pcall(L, 0, 0, 0))
{
ShowError("Error reading 'table.lua'\n");
return;
}
lua_getglobal(L, "Consume");
....
lua_getfield(L, -1, "Value");
lua_getfield(L, -1, "Request");
....
lua_getfield(L, -1, "Enable");
lua_getfield(L, -1, "Name");
lua_close(L);
printf("Read Table complete.\n");
}
I'm using lua 5.4