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