-
Notifications
You must be signed in to change notification settings - Fork 2
Scripting
Zenith includes an abstract script manager interface that we can derive and tailor to virtually any scripting language. Currently the engine makes use of Lua for any and all scripting, using the modern sol2 Lua binding library.
Our first point of contact with the scripting system is the ZLuaScriptManager class, derived from the ZScriptManager interface. This class is initialized as a subsystem on engine initialization, so we can access it directly through the ScriptManager
static method. There are two key operations we can perform with the Lua script manager: execute a script and access the Lua state.
We can execute a script by passing in the raw script code or a path to a Lua script file:
ZEngine::ScriptManager()->ExecuteFile(scriptPath);
ZEngine::ScriptManager()->ExecuteString(rawLuaCode);
We can access the sol2 Lua state by simply calling the getter:
ZEngine::ScriptManager()->LuaState();
Zenith exposes a few core global methods to the Lua runtime. If you wish to add your own methods, simply define your own static method in the ZScriptInternalExports class, and make sure to register it within the ZScriptExports::Register
method.