diff options
Diffstat (limited to 'lib/supple/track.lua')
-rw-r--r-- | lib/supple/track.lua | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/supple/track.lua b/lib/supple/track.lua new file mode 100644 index 0000000..c652281 --- /dev/null +++ b/lib/supple/track.lua @@ -0,0 +1,57 @@ +-- lib/supple/track.lua +-- +-- Sandbox (for) Untrusted Procedure Partitioning (in) Lua Engine +-- +-- Tracking and logging for debug porpoises. +-- +-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org> +-- +-- 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 + depth = depth - 1 + record("<<<", ...) + end +end + +local function start_tracking() + depth, track = 0, {} +end + +local function stop_tracking() + 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, +}
\ No newline at end of file |