Supporting different argument types
In the last chapter, we implemented our C++ function to call a Lua function as follows:
std::string call(const std::string &function, const std::string ¶m);
Our goal in this step is to make it more general and we want the following instead:
LuaValue call(const std::string &function, const LuaValue ¶m);
In fact, go ahead and change this in LuaExecutor.h
. To make it work, we will implement helper functions to push onto and pop from the Lua stack, with our LuaValue
C++ type instead of std::string
. Let us work on pushing onto the stack first.
Pushing onto the stack
In the previous call function, we pushed the param
argument of the std::string
type onto the Lua stack with the following:
lua_pushstring(L, param.c_str());
To...