|
R-Type
Distributed multiplayer game engine in C++
|
Manages Lua state and script execution for the server. More...
#include <LuaEngine.hpp>

Public Member Functions | |
| LuaEngine (const std::string &scriptPath="server/Scripting/scripts/") | |
| Constructor with scripts directory path. | |
| void | setWorld (ecs::wrapper::ECSWorld *world) |
| Set the ECS world for entity operations. | |
| bool | loadScript (const std::string &scriptPath) |
| Load and cache a Lua script. | |
| void | executeUpdate (const std::string &scriptPath, ecs::wrapper::Entity entity, float deltaTime) |
| Execute onUpdate function for an entity's script. | |
| void | executeOnGameStart (const std::string &scriptPath, ecs::wrapper::Entity entity) |
| Execute onGameStart function for an entity's script. | |
| template<typename... Args> | |
| void | callFunction (const std::string &scriptPath, const std::string &functionName, Args &&...args) |
| Call a specific Lua function. | |
| sol::state & | getLuaState () |
| Get direct access to Lua state (advanced usage). | |
| void | registerGameStartCallback (sol::function callback) |
| Register a Lua callback to be called when the game starts. | |
| void | fireGameStartCallbacks (const std::string &roomId) |
| Fire all registered game start callbacks. | |
| void | cleanupEntity (uint32_t entityId) |
| Clean up script cache for a destroyed entity. | |
Private Member Functions | |
| void | initializeBindings () |
Private Attributes | |
| sol::state | _lua |
| std::string | _scriptPath |
| std::unordered_map< std::string, sol::table > | _scriptCache |
| std::unordered_map< uint32_t, std::unordered_map< std::string, sol::table > > | _entityScriptCache |
| ecs::wrapper::ECSWorld * | _world |
| bool | _bindingsInitialized |
| std::recursive_mutex | _luaMutex |
| std::vector< sol::function > | _gameStartCallbacks |
Manages Lua state and script execution for the server.
Handles loading, caching, and executing Lua scripts associated with entities. Provides bindings for ECS components and game logic.
Definition at line 28 of file LuaEngine.hpp.
|
explicit |
Constructor with scripts directory path.
| scriptsPath | Base path for Lua scripts |
Definition at line 21 of file LuaEngine.cpp.
References _lua, LOG_INFO, and LOG_WARNING.
| void scripting::LuaEngine::callFunction | ( | const std::string & | scriptPath, |
| const std::string & | functionName, | ||
| Args &&... | args | ||
| ) |
Call a specific Lua function.
| scriptPath | Path to the script |
| functionName | Name of the function to call |
| args | Variadic arguments to pass to Lua |
Definition at line 284 of file LuaEngine.cpp.
References _bindingsInitialized, _luaMutex, _scriptCache, _world, loadScript(), LOG_ERROR, and LOG_WARNING.

| void scripting::LuaEngine::cleanupEntity | ( | uint32_t | entityId | ) |
Clean up script cache for a destroyed entity.
| entityId | The ID of the entity to clean up |
Definition at line 346 of file LuaEngine.cpp.
References _entityScriptCache, _luaMutex, and LOG_DEBUG.
Referenced by scripting::LuaSystemAdapter::update().
| void scripting::LuaEngine::executeOnGameStart | ( | const std::string & | scriptPath, |
| ecs::wrapper::Entity | entity | ||
| ) |
Execute onGameStart function for an entity's script.
| scriptPath | Path to the script |
| entity | Entity wrapper |
Definition at line 153 of file LuaEngine.cpp.
References _bindingsInitialized, _luaMutex, _scriptCache, _world, loadScript(), LOG_ERROR, and LOG_WARNING.

| void scripting::LuaEngine::executeUpdate | ( | const std::string & | scriptPath, |
| ecs::wrapper::Entity | entity, | ||
| float | deltaTime | ||
| ) |
Execute onUpdate function for an entity's script.
| scriptPath | Path to the script |
| entity | Entity wrapper |
| deltaTime | Frame delta time |
Definition at line 193 of file LuaEngine.cpp.
References _bindingsInitialized, _luaMutex, _scriptCache, _world, loadScript(), LOG_ERROR, and LOG_WARNING.
Referenced by scripting::LuaSystemAdapter::update().

| void scripting::LuaEngine::fireGameStartCallbacks | ( | const std::string & | roomId | ) |
Fire all registered game start callbacks.
| roomId | The ID of the room where the game started |
Definition at line 320 of file LuaEngine.cpp.
References _gameStartCallbacks, _luaMutex, LOG_DEBUG, LOG_ERROR, and LOG_INFO.
|
inline |
Get direct access to Lua state (advanced usage).
Definition at line 82 of file LuaEngine.hpp.
References _lua.
|
private |
Definition at line 47 of file LuaEngine.cpp.
References _lua, _world, scripting::bindings::bindComponents(), scripting::bindings::bindEntity(), scripting::bindings::bindServerGame(), and scripting::bindings::bindWorld().
Referenced by setWorld().

| bool scripting::LuaEngine::loadScript | ( | const std::string & | scriptPath | ) |
Load and cache a Lua script.
| scriptPath | Relative path to script file |
Definition at line 60 of file LuaEngine.cpp.
References _lua, _luaMutex, _scriptCache, _scriptPath, LOG_ERROR, and LOG_INFO.
Referenced by callFunction(), executeOnGameStart(), and executeUpdate().
| void scripting::LuaEngine::registerGameStartCallback | ( | sol::function | callback | ) |
Register a Lua callback to be called when the game starts.
| callback | Lua function to call |
Definition at line 313 of file LuaEngine.cpp.
References _gameStartCallbacks, _luaMutex, and LOG_DEBUG.
| void scripting::LuaEngine::setWorld | ( | ecs::wrapper::ECSWorld * | world | ) |
Set the ECS world for entity operations.
This method must be called before executing any Lua scripts that interact with entities or components. It initializes the Lua bindings with the world context.
| world | Pointer to the ECS world (must not be nullptr) |
| std::invalid_argument | if world is nullptr |
Definition at line 30 of file LuaEngine.cpp.
References _bindingsInitialized, _world, initializeBindings(), LOG_ERROR, LOG_INFO, and LOG_WARNING.

|
private |
Definition at line 109 of file LuaEngine.hpp.
Referenced by callFunction(), executeOnGameStart(), executeUpdate(), and setWorld().
|
private |
Definition at line 107 of file LuaEngine.hpp.
Referenced by cleanupEntity().
|
private |
Definition at line 116 of file LuaEngine.hpp.
Referenced by fireGameStartCallbacks(), and registerGameStartCallback().
|
private |
Definition at line 103 of file LuaEngine.hpp.
Referenced by getLuaState(), initializeBindings(), loadScript(), and LuaEngine().
|
mutableprivate |
Definition at line 110 of file LuaEngine.hpp.
Referenced by callFunction(), cleanupEntity(), executeOnGameStart(), executeUpdate(), fireGameStartCallbacks(), loadScript(), and registerGameStartCallback().
|
private |
Definition at line 105 of file LuaEngine.hpp.
Referenced by callFunction(), executeOnGameStart(), executeUpdate(), and loadScript().
|
private |
Definition at line 104 of file LuaEngine.hpp.
Referenced by loadScript().
|
private |
Definition at line 108 of file LuaEngine.hpp.
Referenced by callFunction(), executeOnGameStart(), executeUpdate(), initializeBindings(), and setWorld().