Improvements for extern C scriptoptions calling
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2019-08-24 18:52:11 +02:00
parent df755fcdd3
commit 5b7da77027
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 21 additions and 21 deletions

View File

@ -645,13 +645,13 @@ namespace Porygon::Binder {
auto opt = this->_scriptData->GetScriptOptions();
auto transformedKey = Utilities::StringUtils::FromUTF8(key);
delete boundParameter;
if (!opt->DoesModuleExist(transformedKey)) {
if (!opt->DoesModuleExist(transformedKey.c_str(), transformedKey.size())) {
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::ModuleDoesntExist,
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) {
for (const auto &v: *module->GetScriptVariables()) {
auto type = module->GetVariableType(v.first);

View File

@ -14,12 +14,12 @@ void Porygon::ScriptOptions::DefaultPrint(const char16_t *s) {
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;
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);
std::basic_stringstream<char16_t> stringStream;
stringStream << stream.rdbuf();
@ -32,11 +32,11 @@ extern "C"{
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);
}
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);
}
@ -48,11 +48,11 @@ extern "C"{
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);
}
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);
}
}

View File

@ -9,12 +9,12 @@ namespace Porygon{
class ScriptOptions{
static Porygon::ScriptOptions DefaultScriptOptions;
static void DefaultPrint(const char16_t* s);
static bool DefaultModuleExists(const std::string& moduleName);
static Script* DefaultResolveModule(const std::string& moduleName);
static bool DefaultModuleExists(const char* moduleName, size_t size);
static Script* DefaultResolveModule(const char* moduleName, size_t size);
void (*_print)(const char16_t* s) = DefaultPrint;
bool (*_doesModuleExist)(const std::string& moduleName) = DefaultModuleExists;
Script* (*_resolveModule)(const std::string& moduleName) = DefaultResolveModule;
bool (*_doesModuleExist)(const char* moduleName, size_t size) = DefaultModuleExists;
Script* (*_resolveModule)(const char* moduleName, size_t size) = DefaultResolveModule;
static std::streambuf* _printBuffer;
static std::ostream* _printStream;
@ -28,23 +28,23 @@ namespace Porygon{
this -> _print(s);
}
inline bool DoesModuleExist(std::string moduleName) const{
return _doesModuleExist(std::move(moduleName));
[[nodiscard]] inline bool DoesModuleExist(const char* moduleName, size_t size) const{
return _doesModuleExist(moduleName, size);
}
inline Script* ResolveModule(std::string moduleName) const{
return _resolveModule(std::move(moduleName));
[[nodiscard]] inline Script* ResolveModule(const char* moduleName, size_t size) const{
return _resolveModule(moduleName, size);
}
void SetPrintFunc(void (*print)(const char16_t *)){
this -> _print = print;
}
void SetModuleExistsFunc(bool (*doesModuleExist)(const std::string& moduleName)){
void SetModuleExistsFunc(bool (*doesModuleExist)(const char* moduleName, size_t size)){
this ->_doesModuleExist = doesModuleExist;
}
void SetResolveModuleFunc(Script* (*resolveModule)(const std::string& moduleName)){
void SetResolveModuleFunc(Script* (*resolveModule)(const char* moduleName, size_t size)){
this ->_resolveModule = resolveModule;
}

View File

@ -30,11 +30,11 @@ class ModuleHandler{
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();
}
inline static Script* ResolveModule(const string& moduleName){
inline static Script* ResolveModule(const char* moduleName, size_t size){
return GetInternal()->MODULES[moduleName];
}