Intro to the LuaAPI
Declare and initialise a uair::LuaAPI object. A LuaAPI object can be default constructed or move constructed (assigned and swapped) but not copy constructed.
uair::LuaAPI luaAPI;
uair::LuaAPI takes the whitelist approach meaning that nothing is available in the environment by default. In order to be of any use, required functions (including both lua functions and user registered custom functions) must be first added to the whitelist and then a new sandbox environment must be created (using the new whitelist).
luaAPI.AddWhitelist("print");
luaAPI.CreateSandbox();
Lua scripts are passed to a uair::LuaAPI instance via a std::string through the CallString functions. There are overloads to pass a variable number of parameters to the script and to recieve multiple return values. There is also a version that forgoes automatic stack management.
try {
// create the string that contains our lua script
std::string script = R"(
print("Knock knock.")
)";
// call the script with automatic stack management
// (no paramaters or return values
luaAPI.CallString(scr);
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}