我从lua的世界开始,目前我正在使用C代码创建表读数
我有一个表,看起来像这样:
Consume =
{
Consume_first = {
Value = 100
Request = 200
},
Require_var = {
Enable= true
Name = "Am"
}
}
我想知道一些情况
冲减定义为lua_getglobal(L, "Consume")
;
值、请求、启用和名称是否使用lua_getfield
函数?
示例:lua_getfield(L, 1, "Value")
在Consume_first和Require_var中,我应该使用什么来定义它们?
我的代码:
void read_table(void) {
lua_State *L;
L = luaL_newstate();
luaL_openlibs(L);
if (luaL_loadfile(L, "table.lua") || lua_pcall(L, 0, 0, 0))
{
ShowError("Error reading 'table.lua'\n");
return;
}
lua_getglobal(L, "Consume");
....
lua_getfield(L, -1, "Value");
lua_getfield(L, -1, "Request");
....
lua_getfield(L, -1, "Enable");
lua_getfield(L, -1, "Name");
lua_close(L);
printf("Read Table complete.\n");
}
我使用的是lua 5.4
1条答案
按热度按时间ygya80vv1#
大概是这样的:
如果您对索引感到困惑,也可以使用
lua_gettop
来帮助您。