Create reading of a moon bool function

3

Well I'm learning the moon and I'm having a question, I'm trying to create the reading of a bool function on the moon.

I have a function that disables or activates as I mark true or false.

This function is called useappenabled , but I am not able to apply it to the moon, before I used it in libconf format and it worked normally before it was written as follows.

On the moon the function is as follows:

Enableapp = 
{
    Useapp = true;
};

Now the above reading in libconfig format was as follows, notice that the useappenabled function is applied to the input value, either 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 the moon, but I'm not able to read the useappenabled function, the code is as follows on the moon

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 like this:

useappenabled = value_de_Useapp;

But I'm starting now, can anyone tell me how I can apply the function useappenabled to equal the value of Useapp .

    
asked by anonymous 05.10.2015 / 21:33

1 answer

1

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 .

    
23.05.2018 / 13:28