Allow passing custom scriptoptions
This commit is contained in:
parent
1fcde396c3
commit
e913f8d052
|
@ -8,8 +8,8 @@
|
|||
#include "Binder/Binder.hpp"
|
||||
#include "EvaluateResult.hpp"
|
||||
|
||||
Porygon::Script* Porygon::Script::Create(const u16string& script) {
|
||||
return new Script(script);
|
||||
Porygon::Script* Porygon::Script::Create(const u16string& script, ScriptOptions* options) {
|
||||
return new Script(script, options);
|
||||
}
|
||||
|
||||
std::u16string To_UTF16(const string &s)
|
||||
|
@ -17,16 +17,16 @@ std::u16string To_UTF16(const string &s)
|
|||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
|
||||
return conv.from_bytes(s);
|
||||
}
|
||||
Porygon::Script *Porygon::Script::Create(const string &script) {
|
||||
return Script::Create(To_UTF16(script));
|
||||
Porygon::Script *Porygon::Script::Create(const string &script, ScriptOptions* options) {
|
||||
return Script::Create(To_UTF16(script), options);
|
||||
}
|
||||
|
||||
Porygon::Script::Script(const u16string& s)
|
||||
Porygon::Script::Script(const u16string& s, ScriptOptions* options)
|
||||
: Diagnostics(make_shared<Diagnostics::DiagnosticsHolder>(s)),
|
||||
_boundScript(nullptr),
|
||||
_scriptVariables(new map<Utilities::HashedString, EvalValuePointer>()),
|
||||
_scriptTypes(new unordered_map<Utilities::HashedString, shared_ptr<ScriptType>>{}),
|
||||
_scriptOptions(nullptr)
|
||||
_scriptOptions(options)
|
||||
{
|
||||
_evaluator = new Evaluator(this -> _scriptVariables, this -> GetScriptOptions());
|
||||
this -> Parse(s);
|
||||
|
|
|
@ -24,14 +24,14 @@ namespace Porygon{
|
|||
shared_ptr<const ScriptType> _returnType = nullptr;
|
||||
ScriptOptions* _scriptOptions;
|
||||
|
||||
explicit Script(const u16string&);
|
||||
explicit Script(const u16string&, ScriptOptions*);
|
||||
Script(shared_ptr<BoundScriptStatement> boundScript, shared_ptr<Diagnostics::DiagnosticsHolder> diagnostics);
|
||||
void Parse(const u16string& script);
|
||||
public:
|
||||
shared_ptr<Diagnostics::DiagnosticsHolder> Diagnostics;
|
||||
|
||||
static Script* Create(const u16string& script);
|
||||
static Script* Create(const string& script);
|
||||
static Script* Create(const u16string& script, ScriptOptions* = nullptr);
|
||||
static Script* Create(const string& script, ScriptOptions* = nullptr);
|
||||
static Script* Clone(const Script* script);
|
||||
|
||||
~Script();
|
||||
|
|
|
@ -31,4 +31,28 @@ extern "C"{
|
|||
void SetDefaultPrintFunc(void (*func)(const char16_t*)){
|
||||
Porygon::ScriptOptions::GetDefaultScriptOptions()->SetPrintFunc(func);
|
||||
}
|
||||
|
||||
void SetDefaultModuleExists(bool (*func)(const std::string& moduleName)){
|
||||
Porygon::ScriptOptions::GetDefaultScriptOptions()->SetModuleExistsFunc(func);
|
||||
}
|
||||
|
||||
void SetDefaultResolveModule(Porygon::Script * (*func)(const std::string& moduleName)){
|
||||
Porygon::ScriptOptions::GetDefaultScriptOptions()->SetResolveModuleFunc(func);
|
||||
}
|
||||
|
||||
Porygon::ScriptOptions* CreateOptions(){
|
||||
return new Porygon::ScriptOptions();
|
||||
}
|
||||
|
||||
void SetOptionPrintFunc(Porygon::ScriptOptions* opt, void (*func)(const char16_t*)){
|
||||
opt->SetPrintFunc(func);
|
||||
}
|
||||
|
||||
void SetOptionModuleExistsFunc(Porygon::ScriptOptions* opt, bool (*func)(const std::string& moduleName)){
|
||||
opt->SetModuleExistsFunc(func);
|
||||
}
|
||||
|
||||
void SetOptionResolveModuleFunc(Porygon::ScriptOptions* opt, bool (*func)(const std::string& moduleName)){
|
||||
opt->SetModuleExistsFunc(func);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue