63 lines
2.0 KiB
C++
63 lines
2.0 KiB
C++
#ifndef PORYGONLANG_SCRIPTOPTIONS_HPP
|
|
#define PORYGONLANG_SCRIPTOPTIONS_HPP
|
|
|
|
#include <string>
|
|
#include <utility>
|
|
namespace Porygon{
|
|
class Script;
|
|
|
|
class ScriptOptions{
|
|
static Porygon::ScriptOptions DefaultScriptOptions;
|
|
static void DefaultPrint(const char16_t* s);
|
|
static bool DefaultModuleExists(const char* moduleName, size_t size);
|
|
static Script* DefaultResolveModule(const char* moduleName, size_t size);
|
|
|
|
void (*_print)(const char16_t* s) = DefaultPrint;
|
|
bool (*_doesModuleExist)(const char* moduleName, size_t size) = DefaultModuleExists;
|
|
Script* (*_resolveModule)(const char* moduleName, size_t size) = DefaultResolveModule;
|
|
static std::streambuf* _printBuffer;
|
|
static std::ostream* _printStream;
|
|
|
|
public:
|
|
static Porygon::ScriptOptions* GetDefaultScriptOptions(){
|
|
return &DefaultScriptOptions;
|
|
}
|
|
|
|
|
|
inline void Print(const char16_t* s) const{
|
|
this -> _print(s);
|
|
}
|
|
|
|
[[nodiscard]] inline bool DoesModuleExist(const char* moduleName, size_t size) const{
|
|
return _doesModuleExist(moduleName, size);
|
|
}
|
|
|
|
[[nodiscard]] inline Script* ResolveModule(const char* moduleName, size_t size) const{
|
|
return _resolveModule(moduleName, size);
|
|
}
|
|
|
|
void SetPrintFunc(void (*print)(const char16_t *)){
|
|
this -> _print = print;
|
|
}
|
|
|
|
void SetModuleExistsFunc(bool (*doesModuleExist)(const char* moduleName, size_t size)){
|
|
this ->_doesModuleExist = doesModuleExist;
|
|
}
|
|
|
|
void SetResolveModuleFunc(Script* (*resolveModule)(const char* moduleName, size_t size)){
|
|
this ->_resolveModule = resolveModule;
|
|
}
|
|
|
|
std::ostream& GetPrintStream(){
|
|
return *Porygon::ScriptOptions::_printStream;
|
|
}
|
|
|
|
void SetPrintStream(std::ostream* stream){
|
|
delete ScriptOptions::_printStream;
|
|
ScriptOptions::_printStream = stream;
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif //PORYGONLANG_SCRIPTOPTIONS_HPP
|