【发布时间】:2018-06-14 02:48:38
【问题描述】:
我刚刚在我的项目中用 LuaJIT 替换了 Lua,我得到了错误提示
Use of undeclared identifier 'lua_len'
如何更改 lua_len 使其与 Lua 5.1 和 LuaJIT 兼容?
这是我的代码,它使用来自 SWIG 绑定的lua_len。 (如果有帮助的话)
%typemap(in) (int argc, t_atom *argv)
{
if (!lua_istable(L, $input)) {
SWIG_exception(SWIG_RuntimeError, "argument mismatch: table expected");
}
lua_len(L, $input);
$1 = lua_tointeger(L, -1);
if (!$1) {
SWIG_exception(SWIG_RuntimeError, "table is empty");
}
$2 = (t_atom *)getbytes($1 * sizeof(t_atom));
for (int i=0; i<$1; ++i) {
lua_pushinteger(L, i+1);
lua_gettable(L, $input);
if (lua_isnumber(L, -1)) {
$2[i].a_type = A_FLOAT;
$2[i].a_w.w_float = lua_tonumber(L, -1);
}
else if (lua_isstring(L, -1)) {
$2[i].a_type = A_SYMBOL;
$2[i].a_w.w_symbol = gensym(lua_tostring(L, -1));
}
else {
SWIG_exception(SWIG_RuntimeError, "unhandled argument type");
}
}
}
【问题讨论】:
-
lua_objlen但这在 Lua 5.2 和 5.3 中不起作用。但是,您可以将lua_len移植到 5.1,请参阅 github.com/keplerproject/lua-compat-5.3/blob/…