我的 Lua 表看起来像这样:
qt={
bid_number=20;
ask_number=20;
bid=table of 20 elements;
ask=table of 20 elemens;
}
所以#qt=0
,
我想将此表发送到 C++ dll 并使用其字段。
我该怎么做?
现在我只能在 C++ dll 中使用 tbl={a,b,c}
这样的表。我这样做:
static int forLua_SumArray (lua_State* L) { // Get the length of the table (same as # operator in Lua)
int n = luaL_len(L, 1);
double sum = 0.0;
// For each index from 1 to n, get the table value as a number and add to sum
for (int i = 1; i <= n; ++i) {
lua_rawgeti(L, 1, i);
sum += lua_tonumber(L, -1);
lua_pop(L, 1);
}
lua_pushnumber(L, sum);
return 1;
}
请帮助我开始处理更复杂的表格。
最佳答案
过去我用过sol2 https://github.com/ThePhD/sol2使 Lua/C++ 接口(interface)中的复杂性变得更加简单。
迈克
关于c++ - C++ dll 中的 Lua 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52117933/