我想要一个函数在被 Lua 脚本调用时返回一个(键-值-)表。因此,我必须将表插入堆栈。
我知道如何将整数压入堆栈:state->PushInteger(10)
我也知道它如何处理字符串和其他数字,但我如何将表推送到堆栈,而且我什至如何从 C++ 端创建它?
这个网站通常会很好地解释一切:http://wwhiz.com/LuaPlus/LuaPlus.html 但是我真的很难理解 LuaPlus 是如何工作的。所以在这种情况下,它并没有真正帮助我。 :(
如果有人能在这里帮助我,那就太好了,我真的已经尝试这样做了 3 天了.. :/
最佳答案
该页面的Pushing a LuaObject onto the Lua Stack
部分似乎是我认为的答案。
The cases where you would need to push a LuaObject onto the Lua stack are rare. Nonetheless, the facility is provided through LuaObject's PushStack() function.
LuaObject tableObj(state);
tableObj.AssignNewTable();
tableObj.SetString("Key", "My String");
// It's often good practice to use a LuaAutoBlock here.
tableObj.PushStack(); // Be sure to clean it up when you're done!
关于c++ - LuaPlus:如何将表格插入堆栈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19801619/