1
votes

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.. :/

1
There's a more uptodate one here. Look for Table Creation section. - greatwolf
@greatwolf wow, that one is only 5 years old, not 9. - Bartek Banachewicz
This would be the one for the version that I'm using: github.com/jjensen/luaplus51-all/blob/… jsfiddle.net/dU4Bu - Forivin

1 Answers

2
votes

The Pushing a LuaObject onto the Lua Stack section of that page appears to be the answer I would think.

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!