89 lines
2.4 KiB
C++
89 lines
2.4 KiB
C++
#include "Engine.hpp"
|
|
|
|
#include <angelscript.h>
|
|
#include <format>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <datetime/datetime.h>
|
|
#include <scriptany/scriptany.h>
|
|
#include <scriptstdstring/scriptstdstring.h>
|
|
#include <scriptarray/scriptarray.h>
|
|
#include <scriptdictionary/scriptdictionary.h>
|
|
#include <scriptgrid/scriptgrid.h>
|
|
#include <scripthandle/scripthandle.h>
|
|
#include <scripthelper/scripthelper.h>
|
|
#include <scriptmath/scriptmath.h>
|
|
#include <weakref/weakref.h>
|
|
|
|
|
|
namespace atlas::script::engine {
|
|
|
|
Engine::Engine() {
|
|
// create a new AngelScript engine
|
|
this->asEngine = asCreateScriptEngine();
|
|
if (this->asEngine == nullptr)
|
|
throw std::runtime_error("Could not create the AngelScript Engine.");
|
|
|
|
this->asEngine->SetMessageCallback(asFUNCTION(this->asCallback), nullptr, asCALL_CDECL);
|
|
|
|
// AngelScript standard library
|
|
RegisterScriptArray(this->asEngine, true);
|
|
RegisterScriptGrid(this->asEngine);
|
|
RegisterStdString(this->asEngine);
|
|
RegisterStdStringUtils(this->asEngine);
|
|
RegisterScriptDictionary(this->asEngine);
|
|
RegisterScriptDateTime(this->asEngine);
|
|
RegisterScriptAny(this->asEngine);
|
|
RegisterScriptHandle(this->asEngine);
|
|
RegisterScriptWeakRef(this->asEngine);
|
|
RegisterExceptionRoutines(this->asEngine);
|
|
RegisterScriptMath(this->asEngine);
|
|
|
|
// Virtual file system
|
|
this->fileSystem = std::make_unique<vfs::VirtualFileSystem>();
|
|
}
|
|
|
|
void Engine::asCallback(const asSMessageInfo *message, void *args) {
|
|
std::string type = "UNKNOWN";
|
|
std::ostream* output = &std::cout;
|
|
|
|
// get a representation for the message type
|
|
switch (message->type) {
|
|
case asMSGTYPE_INFORMATION:
|
|
type = "INFO";
|
|
output = &std::cout;
|
|
case asMSGTYPE_WARNING:
|
|
type = "WARN";
|
|
output = &std::cerr;
|
|
case asMSGTYPE_ERROR:
|
|
type = "ERROR";
|
|
output = &std::cerr;
|
|
}
|
|
|
|
// display the message
|
|
|
|
|
|
*output << std::format(
|
|
"{} ({}, {}) [{}] {}",
|
|
message->section,
|
|
message->row,
|
|
message->col,
|
|
type,
|
|
message->message
|
|
) << std::endl;
|
|
}
|
|
|
|
Engine::~Engine() {
|
|
// release the engine
|
|
this->asEngine->ShutDownAndRelease();
|
|
}
|
|
|
|
asIScriptEngine* Engine::getAsEngine() const {
|
|
return this->asEngine;
|
|
}
|
|
|
|
std::shared_ptr<vfs::VirtualFileSystem> Engine::getFileSystem() const {
|
|
return this->fileSystem;
|
|
}
|
|
|
|
}
|