From 9642e87bc8dd7874d60baec3bf6798de8fa525ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guilloux?= Date: Sat, 25 Mar 2023 23:07:47 +0100 Subject: [PATCH] Fix: [Script] Access to enum/consts defined outside of main.nut (#10573) --- src/script/squirrel.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index 2485ed791a..a57d364fb4 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -566,6 +566,10 @@ void Squirrel::Initialize() sq_pushroottable(this->vm); squirrel_register_global_std(this); + + /* Set consts table as delegate of root table, so consts/enums defined via require() are accessible */ + sq_pushconsttable(this->vm); + sq_setdelegate(this->vm, -2); } class SQFile { @@ -764,6 +768,12 @@ void Squirrel::Uninitialize() { ScriptAllocatorScope alloc_scope(this); + /* Remove the delegation */ + sq_pushroottable(this->vm); + sq_pushnull(this->vm); + sq_setdelegate(this->vm, -2); + sq_pop(this->vm, 1); + /* Clean up the stuff */ sq_pop(this->vm, 1); sq_close(this->vm);