### Complete EvoScript Integration Example Source: https://context7.com/sparcle-studio/evoscript/llms.txt This example shows how to set up EvoScript for script registration, compilation, and execution. It includes defining game classes, registering them with the AddressTableGen, compiling scripts, and calling functions within a simulated game loop. Ensure the necessary EvoScript headers are included and paths are correctly set. ```cpp #include #include #include // Game classes to expose to scripts class Vector3 { public: float x, y, z; float Length() { return sqrt(x*x + y*y + z*z); } }; class GameObject { public: std::string name; Vector3 position; void SetPosition(float x, float y, float z) { position = {x, y, z}; } Vector3 GetPosition() { return position; } std::string GetName() { return name; } virtual void OnUpdate(float dt) { } }; int main() { // Setup logging EvoScript::Tools::ESDebug::Log = [](const std::string& msg) { std::cout << "[EvoScript] " << msg << std::endl; }; EvoScript::Tools::ESDebug::Error = [](const std::string& msg) { std::cerr << "[EvoScript ERROR] " << msg << std::endl; }; // Create address table and register API auto* address = new EvoScript::AddressTableGen(); address->RegisterNewClass("Vector3", "GameTypes", { { "float", "x", EvoScript::Public }, { "float", "y", EvoScript::Public }, { "float", "z", EvoScript::Public } }); ESRegisterMethodArg0(EvoScript::Public, address, Vector3, Length, float) address->RegisterNewClass("GameObject", "GameTypes", { { "std::string", "name", EvoScript::Public }, { "Vector3", "position", EvoScript::Public } }, { "string" }); ESRegisterMethod(EvoScript::Public, address, GameObject, SetPosition, void, ESArg3(float x, float y, float z), x, y, z) ESRegisterMethodArg0(EvoScript::Public, address, GameObject, GetPosition, Vector3) ESRegisterMethodArg0(EvoScript::Public, address, GameObject, GetName, std::string) ESRegisterVirtualMethod(EvoScript::Public, address, GameObject, OnUpdate, void, ESArg1(float dt)) // Save headers for script compilation address->Save("./Scripts/Library/"); // Create compiler auto* compiler = new EvoScript::Compiler("./Cache"); compiler->SetApiVersion(address->GetApiVersion()); compiler->AddIncludePath("./Scripts/Library"); // Create and load script auto* script = EvoScript::Script::Allocate( "EnemyController", compiler, address->GetAddresses() ); if (!script->Load("./Scripts/EnemyController", true)) { std::cerr << "Failed to load script!" << std::endl; return -1; } // Create game object and pass to script auto* enemy = new GameObject(); enemy->name = "Goblin"; enemy->position = {10.0f, 0.0f, 5.0f}; typedef void(*InitFnPtr)(GameObject*); auto initFn = script->GetFunction("Init"); if (initFn) { initFn(enemy); } // Game loop for (int i = 0; i < 100; ++i) { float dt = 0.016f; script->Call("Update", dt); } // Cleanup script->Destroy(); script->Free(); compiler->Free(); delete enemy; delete address; return 0; } ``` -------------------------------- ### Configure Evoscript Project with CMake Source: https://github.com/sparcle-studio/evoscript/blob/master/Examples/Scripts/Example-Source/CMakeLists.txt Sets up the CMake build system for the Evoscript project. Specifies C++20 standard and creates a shared library named 'Example'. ```cmake cmake_minimum_required(VERSION 3.16) project(Example) set(CMAKE_CXX_STANDARD 20) set(CMAKE_SHARED_LIBRARY_PREFIX "") add_library(Example SHARED Example.cpp) ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/sparcle-studio/evoscript/blob/master/CMakeLists.txt Sets up the minimum CMake version, project name, C++ standard, and links the executable to the core library. ```cmake cmake_minimum_required(VERSION 3.16) project(EvoScript) set(CMAKE_CXX_STANDARD 20) add_subdirectory(Core) add_executable(EvoScript UnitTests/main4.cpp) target_link_libraries(EvoScript EvoScriptCore) ``` -------------------------------- ### Implement Behaviour System Source: https://context7.com/sparcle-studio/evoscript/llms.txt Register the Behaviour base class and lifecycle methods in the host application, then implement the class in your script files. ```cpp // Host application setup (main.cpp) #include #include auto* address = new EvoScript::AddressTableGen(); // Register the Behaviour base class address->RegisterNewClass("Behaviour", "Behaviour", { "Standard/BehaviourRegistration.h" }, { EvoScript::InheritClass{ "NonCopyable", EvoScript::Public } } ); // Register virtual lifecycle methods ESRegisterVirtualMethod(EvoScript::Public, address, Behaviour, Update, void, ESArg1(float_t dt)) ESRegisterVirtualMethodArg0(EvoScript::Public, address, Behaviour, Awake, void) ESRegisterVirtualMethodArg0(EvoScript::Public, address, Behaviour, Start, void) ESRegisterVirtualMethodArg0(EvoScript::Public, address, Behaviour, Close, void) // Save generated headers address->Save("/Scripts/Library/"); // Create compiler and script auto* compiler = new EvoScript::Compiler("/Cache"); compiler->SetApiVersion(address->GetApiVersion()); auto* script = EvoScript::Script::Allocate("PlayerController", compiler, address->GetAddresses()); script->Load("/Scripts/PlayerController", true); // Call lifecycle methods using standard typedefs script->Call("InitBehaviour"); script->Call("Awake"); script->Call("Start"); // Game loop while (running) { float deltaTime = GetDeltaTime(); script->Call("Update", deltaTime); } script->Call("Close"); script->Call("ReleaseBehaviour"); ``` ```cpp // Script file: PlayerController.h #include "../Library/Behaviour.h" class PlayerController : public Behaviour { public: ~PlayerController() override = default; void Awake() override; void Start() override; void Update(float_t dt) override; void Close() override; }; // Script file: PlayerController.cpp #include "PlayerController.h" // This macro generates the required exported functions REGISTER_BEHAVIOUR(PlayerController) void PlayerController::Awake() { std::cout << "PlayerController awakened!" << std::endl; } void PlayerController::Start() { std::cout << "PlayerController started!" << std::endl; } void PlayerController::Update(float_t dt) { std::cout << "PlayerController update: " << dt << "s" << std::endl; } void PlayerController::Close() { std::cout << "PlayerController closed!" << std::endl; } ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/sparcle-studio/evoscript/blob/master/Examples/Scripts/Example2-Source/CMakeLists.txt Sets up the CMake build system for the project, defining the C++ standard and shared library naming. ```cmake cmake_minimum_required(VERSION 3.16) project(Example2) set(CMAKE_CXX_STANDARD 20) set(CMAKE_SHARED_LIBRARY_PREFIX "") add_library(Example2 SHARED Example.cpp) ``` -------------------------------- ### Configure EvoScript Compiler Source: https://context7.com/sparcle-studio/evoscript/llms.txt Set up the Compiler class for script compilation, including cache directory, compiler paths, API version, include paths, and debugging options. Auto-detection is used if compiler paths are not explicitly set. ```cpp #include // Create a compiler instance with cache directory auto* compiler = new EvoScript::Compiler("/path/to/cache"); // Configure the compiler path (optional - auto-detected if not set) // On Windows: compiler->SetCompilerPath("C:/Program Files/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"); // On Linux: compiler->SetCompilerPath("/usr/bin/g++ "); // Set API version for cache invalidation when API changes compiler->SetApiVersion("12345678"); // Add include paths for script compilation compiler->AddIncludePath("/path/to/library/headers"); compiler->AddIncludePath("/path/to/engine/includes"); // Enable/disable multi-instance support (creates copies of modules for parallel loading) compiler->SetMultiInstances(true); // Enable PDB generation for debugging (Windows only) compiler->SetCompilePDB(true); // Get cache path std::string cachePath = compiler->GetCachePath(); // Returns: "/path/to/cache" // Get current API version std::string apiVersion = compiler->GetAPIVersion(); // Returns: "12345678" ``` -------------------------------- ### Register class methods using EvoScript macros Source: https://context7.com/sparcle-studio/evoscript/llms.txt Utilize registration macros to expose class methods, static methods, and custom logic to the scripting environment. ```cpp #include class Player { public: int health; std::string name; int GetHealth() { return health; } void SetHealth(int h) { health = h; } void TakeDamage(int amount, bool critical) { health -= critical ? amount * 2 : amount; } std::string GetName() { return name; } static Player* Create(const std::string& name) { /* ... */ return nullptr; } virtual void OnSpawn() { } }; auto* address = new EvoScript::AddressTableGen(); // Register class first address->RegisterNewClass("Player", "GameAPI", { { "int", "health", EvoScript::Public }, { "std::string", "name", EvoScript::Public } }); // Register method with no arguments ESRegisterMethodArg0(EvoScript::Public, address, Player, GetHealth, int) ESRegisterMethodArg0(EvoScript::Public, address, Player, GetName, std::string) // Register method with arguments // Arguments: (publicity, address_table, class, method, return_type, arg_types, arg_names) ESRegisterMethod(EvoScript::Public, address, Player, SetHealth, void, ESArg1(int h), h) ESRegisterMethod(EvoScript::Public, address, Player, TakeDamage, void, ESArg2(int amount, bool critical), amount, critical) // Register static method with no arguments ESRegisterStaticMethodArg0(EvoScript::Public, address, Player, GetPlayerCount, int) // Register static method with arguments ESRegisterStaticMethod(EvoScript::Public, address, Player, Create, Player*, ESArg1(const std::string& name), name) // Register virtual method (generates empty virtual in script header) ESRegisterVirtualMethodArg0(EvoScript::Public, address, Player, OnSpawn, void) ESRegisterVirtualMethod(EvoScript::Public, address, Player, OnDamage, void, ESArg1(int amount)) // Register custom method with custom lambda body ESRegisterCustomMethodArg0(EvoScript::Public, address, Player, IsAlive, bool, return ptr->GetHealth() > 0; ) ESRegisterCustomMethod(EvoScript::Public, address, Player, Heal, void, ESArg1(int amount), ptr->SetHealth(ptr->GetHealth() + amount); ) // Register custom static method ESRegisterCustomStaticMethodArg0(EvoScript::Public, address, Player, GetVersion, const char*, return "1.0.0"; ) // Register free function (not a class method) ESRegisterStaticFunc(address, SpawnPlayer, Player*, ESArg1(const std::string& name), "GameAPI", return Player::Create(name); ) ``` -------------------------------- ### Manage Dynamic Modules with IState Source: https://context7.com/sparcle-studio/evoscript/llms.txt Use IState to load dynamic libraries and retrieve function pointers. Ensure the module is unloaded after use to prevent resource leaks. ```cpp #include // Allocate state for a compiled module EvoScript::IState* state = EvoScript::IState::Allocate("/path/to/Module.dll"); // Check if module file exists if (state->Exists()) { // Load the dynamic library if (state->Load()) { // Get function from loaded module typedef void(*InitFnPtr)(); auto initFunc = state->GetFunction("Init"); if (initFunc) { initFunc(); } typedef int(*ProcessFnPtr)(const char*, int); auto processFunc = state->GetFunction("ProcessData"); if (processFunc) { int result = processFunc("test", 42); } // Unload the module when done state->Unload(); } } // Get module path std::string modulePath = state->GetPath(); // Platform-specific extension std::string ext = EvoScript::IState::Extension; // ".dll" on Windows, ".so" on Linux // Script class provides access to its internal state EvoScript::Script* script = /* ... */; EvoScript::IState* scriptState = script->GetState(); auto fn = scriptState->GetFunction("CustomFunction"); ``` -------------------------------- ### Configure Debug Logging Source: https://context7.com/sparcle-studio/evoscript/llms.txt Define logging callbacks in the host application before initializing EvoScript components to capture library output. ```cpp #include #include // Configure logging callbacks before using EvoScript EvoScript::Tools::ESDebug::Log = [](const std::string& msg) { std::cout << "[LOG] " << msg << std::endl; }; EvoScript::Tools::ESDebug::Info = [](const std::string& msg) { std::cout << "[INFO] " << msg << std::endl; }; EvoScript::Tools::ESDebug::Warn = [](const std::string& msg) { std::cerr << "[WARN] " << msg << std::endl; }; EvoScript::Tools::ESDebug::Error = [](const std::string& msg) { std::cerr << "[ERROR] " << msg << std::endl; }; // Now EvoScript will use these callbacks for all logging auto* compiler = new EvoScript::Compiler("/cache"); // Logs: [LOG] Compiler initialized... ``` -------------------------------- ### Load and Invoke Script Functions with EvoScript Script Class Source: https://context7.com/sparcle-studio/evoscript/llms.txt Manage loaded script modules, retrieve function pointers, and invoke functions directly or via predefined lifecycle callbacks. Ensure the compiler and address table are set up before allocating the script. ```cpp #include #include // Create compiler and address table auto* compiler = new EvoScript::Compiler("/cache"); auto* addressTable = new EvoScript::AddressTableGen(); // ... register classes and methods to addressTable ... compiler->SetApiVersion(addressTable->GetApiVersion()); // Allocate a new script with method pointers from address table auto* script = EvoScript::Script::Allocate( "MyScript", // Script name compiler, // Compiler instance addressTable->GetAddresses() // Method setter functions ); // Load and compile script from source directory bool success = script->Load("/path/to/MyScript", true); // true = compile if needed // Get script information std::string name = script->GetName(); // "MyScript" std::string path = script->GetPath(); // "/path/to/MyScript" bool isDebug = script->IsDebug(); // true in Debug builds // Check if script source has changed bool dirty = script->IsDirty(); // Get a function pointer by name typedef void(*ProcessFnPtr)(MyClass*); auto processFunc = script->GetFunction("Process"); if (processFunc) { MyClass* obj = new MyClass(); processFunc(obj); } // Check if function exists bool hasUpdate = script->HasFunction("Update"); // Call functions directly by name with return value typedef int(*SumFnPtr)(int, int); int result = script->Call("Sum", 5, 10); // Returns: 15 // Call void functions by name typedef void(*UpdateFnPtr)(float); script->Call("Update", 0.016f); // Using predefined typedefs for lifecycle functions script->Call("Awake"); script->Call("Start"); script->Call("Update", 0.016f); script->Call("Close"); // Clean up script->Destroy(); script->Free(); ``` -------------------------------- ### Generate script-accessible headers with AddressTableGen Source: https://context7.com/sparcle-studio/evoscript/llms.txt Use AddressTableGen to register classes, enums, and types, then save the generated header files to a specified directory. ```cpp #include auto* address = new EvoScript::AddressTableGen(); // Register a header file to contain generated code address->RegisterHeader("GameAPI", { "string", "vector" }); // Register a new class with properties address->RegisterNewClass( "Player", // Class name "GameAPI", // Header name { "string", "iostream" }, // Required includes { // Inheritance EvoScript::InheritClass{ "Entity", EvoScript::Public } } ); // Register an enum address->RegisterEnum( "PlayerState", // Enum name "GameAPI", // Header name true, // As enum class { // Values { "Idle", 0 }, { "Walking", 1 }, { "Running", 2 }, { "Jumping", 3 } } ); // Register a typedef address->RegisterTypedef("PlayerId", "GameAPI", "uint32_t"); // Register a using declaration address->RegisterUsing("PlayerList", "GameAPI", "std::vector"); // Add incomplete type declaration (forward declaration) address->AddIncompleteType("GameWorld", "GameAPI"); // Get generated API hash for version tracking std::string apiVersion = address->GetApiVersion(); // Hash as string // Get method pointer setters for Script allocation auto methodPointers = address->GetAddresses(); // Store custom pointers for retrieval in scripts GameEngine* engine = new GameEngine(); address->SetPointer(engine); // Retrieve stored pointer GameEngine* retrieved = address->GetPointer(); // Save generated headers to library folder address->Save("/path/to/Scripts/Library/"); // Creates: /path/to/Scripts/Library/GameAPI.h ``` -------------------------------- ### Configure CMake for EvoScript Project Source: https://github.com/sparcle-studio/evoscript/blob/master/Examples/Scripts/Test-Source/CMakeLists.txt Sets the minimum CMake version, project name, C++ standard to 20, and configures shared library naming. Use this to define the build environment for your EvoScript C++ project. ```cmake cmake_minimum_required(VERSION 3.16) project(Example2) set(CMAKE_CXX_STANDARD 20) set(CMAKE_SHARED_LIBRARY_PREFIX "") add_library(Test SHARED Test.cpp) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.