#include #include #include #include #include #include #include "script/engine/Engine.hpp" #include "script/module/debug/_load.hpp" #include "script/module/filesystem/_load.hpp" #include "script/module/test/_load.hpp" int main_AngelScript(int argc, char* argv[]) { int error; // engine const auto* atlasEngine = new atlas::script::engine::Engine(); auto* asEngine = atlasEngine->getAsEngine(); // functions // atlas::script::module::test::load(atlasEngine); atlas::script::module::debug::load(atlasEngine); atlas::script::module::filesystem::load(atlasEngine); // script CScriptBuilder builder; error = builder.StartNewModule(asEngine, "script"); if (error < 0) throw std::runtime_error("Could not start a new module."); error = builder.AddSectionFromFile(".mods/Atlas/scripts/hello.as"); 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(); delete atlasEngine; return error; } int main_vfspp(int argc, char* argv[]) { int error; // create a virtual file system const auto vfs = std::make_unique(); vfs->mount(".mods/Atlas/assets", "assets"); // get an example file auto file = vfs->resolve("assets/message.txt"); // open and read it auto stream = std::ifstream(file); if (!stream.is_open()) throw std::runtime_error("Could not open the file."); std::string line; std::getline(stream, line); std::cout << line; return 0; } int main(int argc, char* argv[]) { main_AngelScript(argc, argv); }