Atlas-Launcher/source/script/module/filesystem/_load.cpp

64 lines
5 KiB
C++

#include "_load.hpp"
#include <cassert>
#include "Path.hpp"
#include "FileSystem.hpp"
namespace atlas::script::module::filesystem {
void load(const engine::Engine* atlasEngine) {
asIScriptEngine* asEngine = atlasEngine->getAsEngine();
auto* fileSystem = new FileSystem(atlasEngine->getFileSystem());
int error;
// start namespace
error = asEngine->SetDefaultNamespace("atlas::filesystem"); assert(error >= 0);
// file type
error = asEngine->RegisterObjectType("File", 0, asOBJ_REF); assert(error >= 0);
error = asEngine->RegisterObjectBehaviour("File", asBEHAVE_ADDREF, "void f()", asMETHOD(File, asAddReference), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectBehaviour("File", asBEHAVE_RELEASE, "void f()", asMETHOD(File, asRelease), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("File", "void open()", asMETHOD(File, open), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("File", "array<uint8>@ read(uint64 size)", asMETHOD(File, read), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("File", "void write(const array<uint8> &in data)", asMETHOD(File, write), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("File", "uint64 tell()", asMETHOD(File, tell), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("File", "void seek(uint64 position)", asMETHOD(File, seek), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("File", "void close()", asMETHOD(File, close), asCALL_THISCALL); assert(error >= 0);
// path type
error = asEngine->RegisterObjectType("Path", 0, asOBJ_REF); assert(error >= 0);
error = asEngine->RegisterObjectBehaviour("Path", asBEHAVE_ADDREF, "void f()", asMETHOD(Path, asAddReference), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectBehaviour("Path", asBEHAVE_RELEASE, "void f()", asMETHOD(Path, asRelease), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "Path@ getParent() const", asMETHOD(Path, getParent), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "array<Path@>@ getChildrens(bool recursive, const string &in pattern) const", asMETHOD(Path, getChildrens), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "bool exists() const", asMETHOD(Path, exists), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "bool isFile() const", asMETHOD(Path, isFile), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "bool isDirectory() const", asMETHOD(Path, isDirectory), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "File@ open(const string &in mode) const", asMETHOD(Path, open), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "bool mkdir(bool parents) const", asMETHOD(Path, mkdir), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "void remove(bool recursive) const", asMETHOD(Path, remove), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "string getPath() const", asMETHOD(Path, getPath), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "string getDirname() const", asMETHOD(Path, getDirname), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "string getFilename() const", asMETHOD(Path, getFilename), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "string getBasename() const", asMETHOD(Path, getBasename), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "string getSuffix() const", asMETHOD(Path, getSuffix), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "array<string>@ getSuffixes() const", asMETHOD(Path, getSuffixes), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("Path", "array<string>@ getComponents() const", asMETHOD(Path, getComponents), asCALL_THISCALL); assert(error >= 0);
// file system type
error = asEngine->RegisterObjectType("FileSystem", 0, asOBJ_REF); assert(error >= 0);
error = asEngine->RegisterObjectBehaviour("FileSystem", asBEHAVE_ADDREF, "void f()", asMETHOD(FileSystem, asAddReference), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectBehaviour("FileSystem", asBEHAVE_RELEASE, "void f()", asMETHOD(FileSystem, asRelease), asCALL_THISCALL); assert(error >= 0);
error = asEngine->RegisterObjectMethod("FileSystem", "Path@ getPath(const string &in path) const", asMETHOD(FileSystem, getPath), asCALL_THISCALL); assert(error >= 0);
// file system singleton
error = asEngine->RegisterGlobalProperty("const FileSystem fileSystem", fileSystem); assert(error >= 0);
// end namespace
error = asEngine->SetDefaultNamespace(""); assert(error >= 0);
}
}