LuaPlus:如何将表推送到堆栈

LuaPlus: How to push a table to the stack?

本文关键字:堆栈 LuaPlus      更新时间:2023-10-16

我希望函数在被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!