PorygonLang/src/ScriptOptions.hpp

63 lines
2.0 KiB
C++
Raw Normal View History

#ifndef PORYGONLANG_SCRIPTOPTIONS_HPP
#define PORYGONLANG_SCRIPTOPTIONS_HPP
#include <string>
2019-08-10 14:45:15 +00:00
#include <utility>
namespace Porygon{
2019-08-10 14:45:15 +00:00
class Script;
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;
static std::streambuf* _printBuffer;
static std::ostream* _printStream;
2019-08-10 14:45:15 +00:00
public:
static Porygon::ScriptOptions* GetDefaultScriptOptions(){
return &DefaultScriptOptions;
}
2019-08-10 14:45:15 +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));
}
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;
}
std::ostream& GetPrintStream(){
2019-08-10 14:45:15 +00:00
return *Porygon::ScriptOptions::_printStream;
}
void SetPrintStream(std::ostream* stream){
delete ScriptOptions::_printStream;
ScriptOptions::_printStream = stream;
}
};
}
#endif //PORYGONLANG_SCRIPTOPTIONS_HPP