我如何将未知长度的表从 Lua 传递到绑定(bind)的 C++ 函数中?
我希望能够像这样调用 Lua 函数:
call_C_Func({1,1,2,3,5,8,13,21})
然后将表格内容复制到数组中(最好是 STL vector )?
最佳答案
如果您使用 LuaBind就像一个挂号电话一样简单。至于自己卷起来,需要看看lua_next功能。
基本上代码如下:
lua_pushnil(state); // first key
index = lua_gettop(state);
while ( lua_next(state,index) ) { // traverse keys
something = lua_tosomething(state,-1); // tonumber for example
results.push_back(something);
lua_pop(state,1); // stack restore
}
关于c++ - 如何将表从 Lua 传递到 C++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2219669/