-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtrace.lua
More file actions
38 lines (35 loc) · 1.17 KB
/
trace.lua
File metadata and controls
38 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
if string.gsplit == nil and string.split == nil then
function string:gsplit(delimiter)
local function escape_magic(s)
local MAGIC_CHARS_SET = '[()%%.[^$%]*+%-?]'
if s == nil then return end
return (s:gsub(MAGIC_CHARS_SET, '%%%1'))
end
delimiter = delimiter or ' '
if self:sub(-#delimiter) ~= delimiter then self = self .. delimiter end
return self:gmatch('(.-)' .. escape_magic(delimiter))
end
function string:split(delimiter, tabled)
tabled = tabled or false
local ans = {}
for item in self:gsplit(delimiter) do table.insert(ans, item) end
if tabled then return ans end
return unpack(ans)
end
end
local function trace(f, funcName)
if type(f) == 'function' then
return function(...)
local ret = {f(...)}
local s = funcName .. '(' .. getAsString(...) .. ') --> ' .. getAsString(unpack(ret))
print(s)
return unpack(ret)
end
elseif type(f) == 'string' then
funcName = funcName or f
error('not implemented yet')
else
error('invalid arg type')
end
end
return trace