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);
|
|
|
|
static bool DefaultModuleExists(const std::string& moduleName);
|
|
|
|
static Script* DefaultResolveModule(const std::string& moduleName);
|
|
|
|
|
|
|
|
void (*_print)(const char16_t* s) = DefaultPrint;
|
|
|
|
bool (*_doesModuleExist)(const std::string& moduleName) = DefaultModuleExists;
|
|
|
|
Script* (*_resolveModule)(const std::string& moduleName) = 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool DoesModuleExist(std::string moduleName) const{
|
|
|
|
return _doesModuleExist(std::move(moduleName));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Script* ResolveModule(std::string moduleName) const{
|
|
|
|
return _resolveModule(std::move(moduleName));
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetModuleExistsFunc(bool (*doesModuleExist)(const std::string& moduleName)){
|
|
|
|
this ->_doesModuleExist = doesModuleExist;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetResolveModuleFunc(Script* (*resolveModule)(const std::string& moduleName)){
|
|
|
|
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
|