Can now have multiple instances of the same script without compile errors

This commit is contained in:
Antoine Pilote
2021-07-10 14:13:05 -04:00
parent 9f4debd0dd
commit 935e0831a7
3 changed files with 50 additions and 13 deletions

View File

@@ -6,18 +6,22 @@ WrenScript::WrenScript(const std::string& path, const std::string& mod, bool isE
{
WrenVM* vm = ScriptingEngine::GetWrenVM();
// Import statement
std::string source = "import \"" + path + "\" for " + mod;
CompiledSuccesfully = true;
// Import file as module
WrenInterpretResult result = wrenInterpret(vm, "main", source.c_str());
if (result != WREN_RESULT_SUCCESS)
CompiledSuccesfully = false;
// Can't import twice the same script, otherwise gives a compile error.
if (!ScriptingEngine::IsScriptImported(path))
{
std::string source = "import \"" + path + "\" for " + mod;
WrenInterpretResult result = wrenInterpret(vm, "main", source.c_str());
if (!CompiledSuccesfully)
return;
if (result != WREN_RESULT_SUCCESS)
CompiledSuccesfully = false;
if (!CompiledSuccesfully)
return;
ScriptingEngine::ImportScript(path);
}
// Get handle to class
wrenEnsureSlots(vm, 1);