Implementing a Lua executor
We will implement a reusable C++ Lua executor class step by step. Let us call it LuaExecutor
. We will continue to improve this executor by adding new functions to it.
How to include the Lua library in C++ code
To work with the Lua library, you only need three header files:
lua.h
for core functions. Everything here has alua_
prefix.lauxlib.h
for the auxiliary library (auxlib
). The auxiliary library provides more helper functions built on top of the core functions inlua.h
. Everything here has aluaL_
prefix.lualib.h
for loading and building Lua libraries. For example, theluaL_openlibs
function opens all standard libraries.
Lua is implemented in C and those three header files are C header files. To work with C++, Lua provides a convenient wrapper, lua.hpp
, whose content is as follows:
extern "C" { #include "lua.h" #include "lualib.h" #include "lauxlib.h" }
In your C++ code, lua...