简体   繁体   中英

LuaPlus: How to push a table to the stack?

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM