【问题标题】:How to add a message of amount of settings如何添加设置数量的消息
【发布时间】:2016-02-15 05:20:20
【问题描述】:

我有一个问题,我想知道是否可以计算函数 lua_getglobal 中存在的设置。

我有一个叫做define.lua的文件他如下:

tbl {
     macro_enable = true;
     macro_value = 100;
     time_expire = 60;
     enable_mac = true;
};

我试图在我的代码中插入一条消息来计算存在设置的数量

代码:

lua_getglobal(L, "tbl");

lua_getfield(L, -1, "macro_enable");
p->macro_enable = lua_toboolean(L, -1);

lua_getfield(L, -1, "macro_value");
p->macro_value = lua_tointeger(L, -1);

lua_getfield(L, -1, "time_expire");
p->time_expire = lua_tointeger(L, -1);

lua_getfield(L, -1, "enable_mac");
p->enable_mac = lua_toboolean(L, -1);

想要添加消息。

printf ("% d configurations have been read");

我尝试多做一个循环,但没有成功

【问题讨论】:

    标签: c loops for-loop lua lua-api


    【解决方案1】:

    如果你不能使用循环,那么从

    开始
    Int count=0;  
    

    并且在每一行你读取一个配置字段:

    Count+=1;  
    

    你的 printf 语句应该说:

    printf ("% d configurations have been read",count);
    

    【讨论】:

    • 想使用循环来避免额外的代码,但是出现以下错误:PANIC: unprotected erro in call to lua API (attempt to index a bollean value)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 2020-07-26
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多