#include #include #include #include #include #include #include "script/engine/Engine.hpp" #include "script/module/debug/load.hpp" int main(int argc, char* argv[]) { int error; // engine const auto atlasEngine = std::make_unique(); auto* asEngine = atlasEngine->getAsEngine(); // functions atlas::script::module::debug::load(atlasEngine.get()); // script CScriptBuilder builder; error = builder.StartNewModule(asEngine, "script"); if (error < 0) throw std::runtime_error("Could not start a new module."); error = builder.AddSectionFromMemory("script", R"( void main() { array data(256); atlas::debug::log("main", "hello world !"); } )"); if (error < 0) throw std::runtime_error("Could not add a section to the module."); error = builder.BuildModule(); if (error < 0) throw std::runtime_error("Could not build the module."); // execution asIScriptModule *module = asEngine->GetModule("script"); if (module == nullptr) throw std::runtime_error("Could not get the module."); asIScriptFunction *function = module->GetFunctionByDecl("void main()"); if (function == nullptr) throw std::runtime_error("Could not get the main function."); asIScriptContext *context = asEngine->CreateContext(); if (context == nullptr) throw std::runtime_error("Could not create the context."); error = context->Prepare(function); if (error < 0) throw std::runtime_error("Could not register the function in the context."); error = context->Execute(); // clean up context->Release(); return error; }