83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <memory>
|
|
|
|
#include <angelscript.h>
|
|
#include <cassert>
|
|
#include <VirtualFileSystem.hpp>
|
|
#include <scriptbuilder/scriptbuilder.h>
|
|
|
|
#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"); assert(error >= 0);
|
|
|
|
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(); assert(error >= 0);
|
|
|
|
// execution
|
|
asIScriptModule *module = asEngine->GetModule("script"); assert(error >= 0);
|
|
|
|
asIScriptFunction *function = module->GetFunctionByDecl("void main()");
|
|
if (function == nullptr)
|
|
throw std::runtime_error("Could not get the main function.");
|
|
|
|
asIScriptContext *context = asEngine->CreateContext(); assert(error >= 0);
|
|
|
|
error = context->Prepare(function); assert(error >= 0);
|
|
|
|
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::VirtualFileSystem>();
|
|
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);
|
|
}
|