c++ - C++ dll 中的 Lua 表

标签 c++ lua

我的 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/

相关文章:

c - 在Lua中,#INF和#IND是什么?

c++ - 我可以检查一个类*不是*默认可构造的吗?

c++ - C/C++ 有哪些图灵完备的宏语言

c++ - 如何在 C++ 中将输入字符串转换为数组?

c++ - 使用 OpenCV 调整图像数组的大小

lua - Lua中如何检查表是否包含某个元素?

file - 如何将文本文件加载到 Lua 中的某种类似表格的变量中?

c++ - 从 COBOL 生成的 .DAT 文件进行数据转换

authentication - OpenWrt:LuCI:如何实现受限用户访问

linux - 如何对 AwesomeWM 文本时钟小部件实现序数日?