-- lib/supple/track.lua -- -- Sandbox (for) Untrusted Procedure Partitioning (in) Lua Engine -- -- Tracking and logging for debug porpoises. -- -- Copyright 2012 Daniel Silverstone -- -- For licence terms, see COPYING -- local depth local track local function record(...) if depth then track[#track+1] = { depth, ... } end end local function enter(...) if depth then record(">>>", ...) depth = depth + 1 end end local function leave(...) if depth then if depth > 0 then depth = depth - 1 end record("<<<", ...) end end local function start_tracking() depth, track = 0, {} end local function stop_tracking() if track == nil then return "***NO TRACKING DATA***" end local ret = {} for i = 1, #track do local ent = track[i] local pfx = (" "):rep(ent[1]) table.remove(ent, 1) ret[#ret+1] = pfx .. table.concat(ent, " ") end depth, track = nil, {} return table.concat(ret, "\n") end return { start = start_tracking, stop = stop_tracking, enter = enter, leave = leave, record = record, }