From 6c59e385daed31f8118fa312133340a856893b7d Mon Sep 17 00:00:00 2001 From: nuoun <10226424+nuoun@users.noreply.github.com> Date: Sun, 11 Aug 2024 19:58:41 +0200 Subject: [PATCH] Fix testrunner warnings (#7745) --- src/common/LuaSupport.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/common/LuaSupport.cpp b/src/common/LuaSupport.cpp index f5a42f4bc4f..6c612ba4bb7 100644 --- a/src/common/LuaSupport.cpp +++ b/src/common/LuaSupport.cpp @@ -136,7 +136,7 @@ int lua_limitRange(lua_State *L) return 1; } -// customized print that outputs limted amount of arguments and restricts use to strings and numbers +// custom print that outputs limited amount of arguments and restricts use to strings and numbers int lua_sandboxPrint(lua_State *L) { #if HAS_LUA @@ -174,10 +174,16 @@ bool Surge::LuaSupport::setSurgeFunctionEnvironment(lua_State *L) lua_pushcfunction(L, lua_sandboxPrint); lua_setfield(L, eidx, "print"); + // add global tables + lua_getglobal(L, "surge"); + lua_setfield(L, eidx, "surge"); + lua_getglobal(L, "shared"); + lua_setfield(L, eidx, "shared"); + // add whitelisted functions and modules - std::vector sandboxWhitelist = {"pairs", "ipairs", "unpack", "next", - "type", "tostring", "tonumber", "setmetatable", - "error", "surge", "shared"}; + std::vector sandboxWhitelist = {"pairs", "ipairs", "unpack", + "next", "type", "tostring", + "tonumber", "setmetatable", "error"}; for (const auto &f : sandboxWhitelist) { lua_getglobal(L, f.c_str()); // stack: f>t>f