From d0db2adafbb8a6beafb0a13aed11697115e98448 Mon Sep 17 00:00:00 2001 From: Rose Liverman Date: Sun, 29 Jun 2025 02:11:40 -0600 Subject: [PATCH] fixing missing pack/unpack closes #1 --- sandbox.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/sandbox.lua b/sandbox.lua index ce345f8..429e839 100644 --- a/sandbox.lua +++ b/sandbox.lua @@ -1,5 +1,5 @@ local sandbox = { - _VERSION = "sandbox 0.5", + _VERSION = "sandbox 0.5.1", _DESCRIPTION = "A pure-lua solution for running untrusted Lua code.", _URL = "https://github.com/kikito/sandbox.lua", _LICENSE = [[ @@ -29,6 +29,24 @@ local sandbox = { } +-- 0.5.1 fixing missing pack and unpack functions for some Lua versions +if not table.pack then + table.pack = function(...) + local t = {...} + t.n = select("#", ...) + return t + end +end +if not table.unpack then + table.unpack = function(tab, start, finish) + local result = {} + for i = start or 1, finish or #tab do + result[#result + 1] = tab[i] + end + return result + end +end + -- quotas don't work in LuaJIT since debug.sethook works differently there local quota_supported = type(_G.jit) == "nil" sandbox.quota_supported = quota_supported