Create reading of a bool function in lua

Asked

Viewed 111 times

3

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

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

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

On the moon is as follows the function:

Enableapp = 
{
    Useapp = true;
};

Now the reading before in libconfig format was the following, note that the useappenabled function is applied the input value, either true or false if I put in the Useapp

if (config_lookup(&onf, "Enableapp"))
        if (config_setting_lookup_bool(cf, "Useapp", &SelectValue))
            useappenabled = SelectValue;

Then I tried to change the libconfig code to moon, however I am not able to read the function useappenabled , 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 more or less like this:

useappenabled = value_de_Useapp;

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

1 answer

1

Use lua_getfield to take the value of a table field:

lua_getglobal(L, "Enableapp");
lua_getfield(L, -1, "Useapp");
useappenabled = lua_toboolean(L,-1);

Note the conversion with lua_toboolean and not with lua_tonumber.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.