如何使函数从lua文件中读取值

时间:2015-10-06 04:00:46

标签: lua

我正在学习lua,我有一个问题,我正试图在lua中创建一个阅读功能bool。

我有一个功能,当我得分为真或假时禁用或启用。

这个函数被称为useappenabled我无法在月球上应用它,之后我以libconfig的形式使用并且在编写之前正常运行,如下所示。

该文件如下:

Enableapp = 
{
    Useapp = true;
};

现在在塑造libconfig之前阅读以下内容,请注意useappenabled函数应用于输入值,即如果我使用Useapp则为true或false。

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

所以我尝试将代码libconfig更改为lua,但是我无法读取useappenabled函数,代码如下所示。

lua_getglobal(L, "Enableapp");
    lua_pushstring(L, "Useapp");
    lua_tonumber(L, useappenabled);

我认为问题是lua_tonumber,我需要做一些或多或少的事情:

useappenabled = value_the_Useapp;

但我现在开始使用lua,有人可以告诉我如何将函数useappenabled应用于等于Useapp值。

1 个答案:

答案 0 :(得分:1)

  

无法在月球上使用

这是大多数Earthly软件的问题。通常的困难是到达月亮。

  

我需要做一些或多或少的事情:

useappenabled = value_the_Useapp;
lua_getglobal(L, "Enableapp"); // push the table onto the stack
lua_getfield(L, -1, "Useapp"); // index table with "Useapp" and push result onto the stack
useappenabled = lua_toboolean(L, -1); // get the value off the top of the stack into your C code
相关问题