PorygonLang/src/ScriptOptions.cpp

33 lines
1.2 KiB
C++
Raw Normal View History

#include <iostream>
2019-08-10 14:45:15 +00:00
#include <filesystem>
#include <fstream>
#include "ScriptOptions.hpp"
#include "Utilities/StringUtils.hpp"
2019-08-10 14:45:15 +00:00
#include "Script.hpp"
Porygon::ScriptOptions Porygon::ScriptOptions::DefaultScriptOptions;
std::streambuf* Porygon::ScriptOptions::_printBuffer = std::cout.rdbuf();
std::ostream* Porygon::ScriptOptions::_printStream = new std::ostream(Porygon::ScriptOptions::_printBuffer);
2019-08-10 14:45:15 +00:00
void Porygon::ScriptOptions::DefaultPrint(const char16_t *s) {
Porygon::ScriptOptions::GetDefaultScriptOptions()->GetPrintStream() << Porygon::Utilities::StringUtils::FromUTF8(s) << std::endl;
}
2019-08-10 14:45:15 +00:00
bool Porygon::ScriptOptions::DefaultModuleExists(const std::string& moduleName) {
return std::filesystem::exists(moduleName);
}
2019-08-10 14:45:15 +00:00
Porygon::Script *Porygon::ScriptOptions::DefaultResolveModule(const std::string& moduleName) {
auto stream = std::ifstream(moduleName);
std::basic_stringstream<char16_t> stringStream;
stringStream << stream.rdbuf();
auto str = std::u16string(stringStream.str());
return Porygon::Script::Create(str);
}
extern "C"{
void SetDefaultPrintFunc(void (*func)(const char16_t*)){
Porygon::ScriptOptions::GetDefaultScriptOptions()->SetPrintFunc(func);
}
}