【发布时间】:2019-01-31 08:48:11
【问题描述】:
我为我的 Lua 项目编写 C++ dll。 Stackoverflow 程序员 Josh Parnell 非常乐于帮助我。他给了我一个代码,里面有luaL_len()。
但是我使用了一个在其中实现了 Lua 5.1.5 的程序。此版本中缺少luaL_len()。
这是一个代码:
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;
}
请帮我做其中一件事或两件事
- 使用一些东西而不是 luaL_len 来获取从 Lua 到 dll 的表的大小
- 让 luaL_len 在我的 Lua 5.1.5 中工作
【问题讨论】: