我有一个名为 GetParameter 的 C 方法,我希望从 Lua 中使用它。该方法将返回一些值到 Lua。
我在 C 中构建表格的方式是最常见的方式:
lua_newtable(L);
for (int i = 0; i < parameters; i++)
{
lua_pushnumber(L,i);
lua_pushstring(L,myParameter);
lua_settable(L,-3);
}
在我看过的所有示例中,此后您需要使用lua setGlobal设置结果表:
//set name for the result
lua_setglobal(ptLuaState, "resultTable");
通过这种方法,我可以在Lua中访问结果表格,如下所示:
GetParameter("V111","V111Parameter")
printTable(resultTable);
做这一切都很顺利,但是有没有另一种不使用setglobal的方法呢?我尝试过像这样做:
local mytable=GetParameter("V111","V111Parameter");
但是它不起作用。使用全局变量更好吗?如何在不使用setglobal的情况下获取结果表格?
提前感谢!