如何我通过一个表从Lua成C ++? [英] How to I pass a table from lua into C++?
本文介绍了如何我通过一个表从Lua成C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将如何通过从Lua未知长度的表到绑定C ++函数?
How would I pass a table of unknown length from lua into a bound C++ function?
我希望能够调用LUA函数是这样的:
I want to be able to call the lua function like this:
call_C_Func({1,1,2,3,5,8,13,21})
和表的内容复制到一个数组(preferably STL的vector)?
And copy the table contents into an array (preferably STL vector)?
推荐答案
如果您使用 LuaBind 一>它为一个注册电话一样简单。至于卷起你自己的,你需要看看 lua_next 功能。
If you use LuaBind it's as simple as one registered call. As for rolling up your own, you need to take a look at lua_next function.
基本上,code是如下:
Basically the code is as follows:
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
}
这篇关于如何我通过一个表从Lua成C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文