1

I want a function to return a (key-value-)table when called by a Lua-script. Therefore I have to push the table to the stack.
I know how to push an integer to the stack: state->PushInteger(10)
I also know how it works for strings and other numbers, but how would I push a table to the stack and furthermore how would I even create it from the C++ side?

This site usually explains everything pretty well: http://wwhiz.com/LuaPlus/LuaPlus.html but I have a really hard time understanding how LuaPlus works. So in this case it doesn't really help me. :(

It would be really nice if someone could help me out here, I'm literally trying to do this for 3 days now.. :/

4

1 回答 1

2

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!
于 2013-11-06T00:33:52.493 回答