如何添加设置金额的信息提示

我有一个问题,想知道是否有可能在函数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个配置已被读取");

我尝试了循环,但没有成功。

点赞
用户4244472
用户4244472

如果不能使用循环,则从以下内容开始:

Int count=0;

并在读取每个配置字段的每一行时进行:

Count+=1;

您的 printf 语句应该是:

printf ("% d configurations have been read",count);
2015-11-13 16:05:06