diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-08-05 11:45:46 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-08-05 11:45:46 +0100 |
commit | b8892dabfc998390722b1c347d4b25cf76b654ac (patch) | |
tree | d63bc717248f4bc644b75e6a9cf80ef2dde9054a /lib/supple/host.lua | |
parent | 5b22c9d8a93762b4b1e2a5682008092f88a8abc1 (diff) | |
download | supple-b8892dabfc998390722b1c347d4b25cf76b654ac.tar.gz |
HOST: Ensure we simplify return values to local types so we can clean down if the function returns tables etc
Diffstat (limited to 'lib/supple/host.lua')
-rw-r--r-- | lib/supple/host.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/supple/host.lua b/lib/supple/host.lua index bac95ae..fe8ccc1 100644 --- a/lib/supple/host.lua +++ b/lib/supple/host.lua @@ -14,11 +14,35 @@ local subprocess = require 'luxio.subprocess' local comms = require 'supple.comms' local objects = require 'supple.objects' +local capi = require 'supple.capi' local hostname = "host" local counter = 0 local limits +local function simplify(t, memo) + if not memo then memo = {} end + if memo[t] then return memo[t] end + local ret = {} + memo[t] = ret + local kk, vv + for k, v in capi.pairs(t) do + kk, vv = k, v + if capi.type(k) == "table" then + kk = simplify(k, memo) + end + if capi.type(v) == "table" then + vv = simplify(v, memo) + end + if capi.rawtype(kk) ~= "userdata" and + capi.rawtype(vv) ~= "userdata" then + -- We've not got a proxy left over anywhere, so copy it + ret[kk] = vv + end + end + return ret +end + local function run_wrapper() local wrapperpath = "@@WRAPPER_BIN@@" -- START_TEST_SUPPLE @@ -80,6 +104,10 @@ local function run_sandbox(codestr, codename, ...) else ok, err = limitsok, limitserr end + -- Convert any complex objects returned to us, so we can clean up... + if ok then + ret = simplify(ret) + end -- We need to clean up, so dump all the objects func = nil -- And ask the supple API to clear down too |