Added extern C support for registering static variables

This commit is contained in:
Deukhoofd 2019-08-18 15:09:44 +02:00
parent e939920e5c
commit 184ef8ec9a
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 15 additions and 1 deletions

View File

@ -1,3 +1,11 @@
#include "StaticScope.hpp" #include "StaticScope.hpp"
Porygon::StandardLibraries::StaticScope::InternalScope* Porygon::StandardLibraries::StaticScope::_internal = nullptr; namespace Porygon::StandardLibraries{
StaticScope::InternalScope* StaticScope::_internal = nullptr;
extern "C"{
void RegisterStaticVariable(uint32_t identifier, ScriptType* type, Evaluation::EvalValue* value){
StaticScope::RegisterVariableRaw(identifier, type, value);
}
}
}

View File

@ -62,6 +62,12 @@ namespace Porygon::StandardLibraries{
GetScope()->_variables.insert({identifier, value}); GetScope()->_variables.insert({identifier, value});
} }
static void RegisterVariableRaw(uint32_t identifier, ScriptType* type, Evaluation::EvalValue* value){
auto hash = Utilities::HashedString::CreateLookup(identifier);
GetScope()->_boundVariables.insert({hash, new Binder::BoundVariable(shared_ptr<ScriptType>(type))});
GetScope()->_variables.insert({hash, value});
}
static Binder::BoundVariable* GetBoundVariable(const Utilities::HashedString &identifier){ static Binder::BoundVariable* GetBoundVariable(const Utilities::HashedString &identifier){
auto found = GetScope()->_boundVariables.find(identifier); auto found = GetScope()->_boundVariables.find(identifier);
if (found != GetScope()->_boundVariables.end()) { if (found != GetScope()->_boundVariables.end()) {