Question:
Well I'm learning lua and I have a doubt, I'm trying to create a bool function reading in lua.
I have a function that turns it off or on as I set it to true or false.
This function is called useappenabled
but I'm not able to apply it in lua, before I used it in libconf format and it worked normally before it was written as follows.
In lua, the function is as follows:
Enableapp =
{
Useapp = true;
};
Now the reading before in libconfig format was as follows, notice that the useappenabled function is applied to the input value, ie true or false if I put it in Useapp
if (config_lookup(&onf, "Enableapp"))
if (config_setting_lookup_bool(cf, "Useapp", &SelectValue))
useappenabled = SelectValue;
So I tried to change the code from libconfig to lua, but I'm not able to read the useappenabled
function, the code is like this in lua
lua_getglobal(L, "Enableapp");
lua_pushstring(L, "Useapp");
lua_tonumber(L, useappenabled);
I think the problem is lua_tonumber, I would need to do something something like this:
useappenabled = value_de_Useapp;
But I'm starting now, does anyone know tell me how I can apply the useappenabled
function to equal the value of Useapp
.
Answer:
Use lua_getfield
to get the value of a field from a table:
lua_getglobal(L, "Enableapp");
lua_getfield(L, -1, "Useapp");
useappenabled = lua_toboolean(L,-1);
Note the conversion with lua_toboolean
and not lua_tonumber
.