Stack Manipulation
Whilst it is never necessary to interact with the stack directly there exists a number of functions to make it easier to both inspect and modify the contents of the stack.
Multiple parameters and return values
try {
// stack size should be 0 initially
std::cout << "Stack: " << luaAPI.GetStackSize() << std::endl;
// add various values to the stack
luaAPI.PushStack(1);
luaAPI.PushStack("Hello");
luaAPI.PushStack(2, "World", 3, 5.5f);
// stack size should now be 6
std::cout << "Stack: " << luaAPI.GetStackSize() << std::endl;
// return the value on top of the stack (doesn't remove it)
float f = luaAPI.ReadStack<float>(luaAPI.GetStackSize());
std::cout << f << std::endl;
// stack size is still 6
std::cout << "Stack: " << luaAPI.GetStackSize() << std::endl;
// remove values from the stack
luaAPI.PopStack(2);
luaAPI.RemoveStack(luaAPI.GetStackSize() - 1);
// stack size is now 3
std::cout << "Stack: " << luaAPI.GetStackSize() << std::endl;
// read the top 2 values off the stack
auto values = luaAPI.ReadStack<std::string,
std::string>(luaAPI.GetStackSize() - 1);
std::cout << std::get<0>(values) << " " <<
std::get<1>(values) << std::endl;
// set the size of the stack to 0 essentially clearing it
luaAPI.SetStackSize(0);
std::cout << "Stack: " << luaAPI.GetStackSize() << std::endl;
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}