Improvements for extern C scriptoptions calling
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
df755fcdd3
commit
5b7da77027
|
@ -645,13 +645,13 @@ namespace Porygon::Binder {
|
||||||
auto opt = this->_scriptData->GetScriptOptions();
|
auto opt = this->_scriptData->GetScriptOptions();
|
||||||
auto transformedKey = Utilities::StringUtils::FromUTF8(key);
|
auto transformedKey = Utilities::StringUtils::FromUTF8(key);
|
||||||
delete boundParameter;
|
delete boundParameter;
|
||||||
if (!opt->DoesModuleExist(transformedKey)) {
|
if (!opt->DoesModuleExist(transformedKey.c_str(), transformedKey.size())) {
|
||||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::ModuleDoesntExist,
|
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::ModuleDoesntExist,
|
||||||
exp->GetStartPosition(),
|
exp->GetStartPosition(),
|
||||||
exp->GetLength());
|
exp->GetLength());
|
||||||
return new BoundBadExpression(exp->GetStartPosition(), exp->GetLength());
|
return new BoundBadExpression(exp->GetStartPosition(), exp->GetLength());
|
||||||
}
|
}
|
||||||
auto module = Script::Clone(opt->ResolveModule(transformedKey));
|
auto module = Script::Clone(opt->ResolveModule(transformedKey.c_str(), transformedKey.size()));
|
||||||
if (module->GetReturnType() == nullptr) {
|
if (module->GetReturnType() == nullptr) {
|
||||||
for (const auto &v: *module->GetScriptVariables()) {
|
for (const auto &v: *module->GetScriptVariables()) {
|
||||||
auto type = module->GetVariableType(v.first);
|
auto type = module->GetVariableType(v.first);
|
||||||
|
|
|
@ -14,12 +14,12 @@ void Porygon::ScriptOptions::DefaultPrint(const char16_t *s) {
|
||||||
Porygon::ScriptOptions::GetDefaultScriptOptions()->GetPrintStream() << Porygon::Utilities::StringUtils::FromUTF8(s) << std::endl;
|
Porygon::ScriptOptions::GetDefaultScriptOptions()->GetPrintStream() << Porygon::Utilities::StringUtils::FromUTF8(s) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Porygon::ScriptOptions::DefaultModuleExists(const std::string& moduleName) {
|
bool Porygon::ScriptOptions::DefaultModuleExists(const char* moduleName, size_t size) {
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
return (stat (moduleName.c_str(), &buffer) == 0);
|
return (stat (moduleName, &buffer) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Porygon::Script *Porygon::ScriptOptions::DefaultResolveModule(const std::string& moduleName) {
|
Porygon::Script *Porygon::ScriptOptions::DefaultResolveModule(const char* moduleName, size_t size) {
|
||||||
auto stream = std::ifstream(moduleName);
|
auto stream = std::ifstream(moduleName);
|
||||||
std::basic_stringstream<char16_t> stringStream;
|
std::basic_stringstream<char16_t> stringStream;
|
||||||
stringStream << stream.rdbuf();
|
stringStream << stream.rdbuf();
|
||||||
|
@ -32,11 +32,11 @@ extern "C"{
|
||||||
Porygon::ScriptOptions::GetDefaultScriptOptions()->SetPrintFunc(func);
|
Porygon::ScriptOptions::GetDefaultScriptOptions()->SetPrintFunc(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDefaultModuleExists(bool (*func)(const std::string& moduleName)){
|
void SetDefaultModuleExists(bool (*func)(const char* moduleName, size_t size)){
|
||||||
Porygon::ScriptOptions::GetDefaultScriptOptions()->SetModuleExistsFunc(func);
|
Porygon::ScriptOptions::GetDefaultScriptOptions()->SetModuleExistsFunc(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDefaultResolveModule(Porygon::Script * (*func)(const std::string& moduleName)){
|
void SetDefaultResolveModule(Porygon::Script * (*func)(const char* moduleName, size_t size)){
|
||||||
Porygon::ScriptOptions::GetDefaultScriptOptions()->SetResolveModuleFunc(func);
|
Porygon::ScriptOptions::GetDefaultScriptOptions()->SetResolveModuleFunc(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,11 +48,11 @@ extern "C"{
|
||||||
opt->SetPrintFunc(func);
|
opt->SetPrintFunc(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetOptionModuleExistsFunc(Porygon::ScriptOptions* opt, bool (*func)(const std::string& moduleName)){
|
void SetOptionModuleExistsFunc(Porygon::ScriptOptions* opt, bool (*func)(const char* moduleName, size_t size)){
|
||||||
opt->SetModuleExistsFunc(func);
|
opt->SetModuleExistsFunc(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetOptionResolveModuleFunc(Porygon::ScriptOptions* opt, Porygon::Script* (*func)(const std::string& moduleName)){
|
void SetOptionResolveModuleFunc(Porygon::ScriptOptions* opt, Porygon::Script* (*func)(const char* moduleName, size_t size)){
|
||||||
opt->SetResolveModuleFunc(func);
|
opt->SetResolveModuleFunc(func);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,12 +9,12 @@ namespace Porygon{
|
||||||
class ScriptOptions{
|
class ScriptOptions{
|
||||||
static Porygon::ScriptOptions DefaultScriptOptions;
|
static Porygon::ScriptOptions DefaultScriptOptions;
|
||||||
static void DefaultPrint(const char16_t* s);
|
static void DefaultPrint(const char16_t* s);
|
||||||
static bool DefaultModuleExists(const std::string& moduleName);
|
static bool DefaultModuleExists(const char* moduleName, size_t size);
|
||||||
static Script* DefaultResolveModule(const std::string& moduleName);
|
static Script* DefaultResolveModule(const char* moduleName, size_t size);
|
||||||
|
|
||||||
void (*_print)(const char16_t* s) = DefaultPrint;
|
void (*_print)(const char16_t* s) = DefaultPrint;
|
||||||
bool (*_doesModuleExist)(const std::string& moduleName) = DefaultModuleExists;
|
bool (*_doesModuleExist)(const char* moduleName, size_t size) = DefaultModuleExists;
|
||||||
Script* (*_resolveModule)(const std::string& moduleName) = DefaultResolveModule;
|
Script* (*_resolveModule)(const char* moduleName, size_t size) = DefaultResolveModule;
|
||||||
static std::streambuf* _printBuffer;
|
static std::streambuf* _printBuffer;
|
||||||
static std::ostream* _printStream;
|
static std::ostream* _printStream;
|
||||||
|
|
||||||
|
@ -28,23 +28,23 @@ namespace Porygon{
|
||||||
this -> _print(s);
|
this -> _print(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool DoesModuleExist(std::string moduleName) const{
|
[[nodiscard]] inline bool DoesModuleExist(const char* moduleName, size_t size) const{
|
||||||
return _doesModuleExist(std::move(moduleName));
|
return _doesModuleExist(moduleName, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Script* ResolveModule(std::string moduleName) const{
|
[[nodiscard]] inline Script* ResolveModule(const char* moduleName, size_t size) const{
|
||||||
return _resolveModule(std::move(moduleName));
|
return _resolveModule(moduleName, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetPrintFunc(void (*print)(const char16_t *)){
|
void SetPrintFunc(void (*print)(const char16_t *)){
|
||||||
this -> _print = print;
|
this -> _print = print;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetModuleExistsFunc(bool (*doesModuleExist)(const std::string& moduleName)){
|
void SetModuleExistsFunc(bool (*doesModuleExist)(const char* moduleName, size_t size)){
|
||||||
this ->_doesModuleExist = doesModuleExist;
|
this ->_doesModuleExist = doesModuleExist;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetResolveModuleFunc(Script* (*resolveModule)(const std::string& moduleName)){
|
void SetResolveModuleFunc(Script* (*resolveModule)(const char* moduleName, size_t size)){
|
||||||
this ->_resolveModule = resolveModule;
|
this ->_resolveModule = resolveModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,11 +30,11 @@ class ModuleHandler{
|
||||||
return _internal;
|
return _internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static bool DoesModuleExist(const string& moduleName){
|
inline static bool DoesModuleExist(const char* moduleName, size_t size){
|
||||||
return GetInternal()->MODULES.find(moduleName) != GetInternal()->MODULES.end();
|
return GetInternal()->MODULES.find(moduleName) != GetInternal()->MODULES.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static Script* ResolveModule(const string& moduleName){
|
inline static Script* ResolveModule(const char* moduleName, size_t size){
|
||||||
return GetInternal()->MODULES[moduleName];
|
return GetInternal()->MODULES[moduleName];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue