-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump.lua
More file actions
60 lines (55 loc) · 1.51 KB
/
dump.lua
File metadata and controls
60 lines (55 loc) · 1.51 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- module to be used as tables pretty-printer
-- https://forum.farmanager.com/viewtopic.php?p=140340#p140340
local dump
local success, inspect = pcall(require, "inspect") --https://github.com/kikito/inspect.lua
if success then
local function process (item)
if type(item)=="string" then
if not item:isvalid() or item==("\0"):rep(16) then
local guid = win.Uuid(item)
item = guid and guid:isvalid() and "win.Uuid'"..guid:upper().."'"
or "<non valid utf8>"..item:clean()
end
elseif type(item)=="userdata" then
if bit64.type(item) then
item = "bit64.new'"..tostring(item).."'"
else
item = assert(sh.sharedUtils.safe_tostring(item))
if not item:find"userdata" then
item = "<userdata>"..item
end
end
end
return item
end
function dump (v)
return inspect(v, {process=process})
end
else
dump = require"moon".dump
end
local function printRet (...)
local n = select("#", ...)
if n==0 then
print "no values returned"
elseif n==1 then
print(dump((...)))
elseif n~=0 then
for i=1,n do
print("value "..i..":", dump(select(i, ...)))
end
end
end
if _cmdline=="" then
print "Dumps specified lua expressions"
print "Usage: dump lua_expression"
print "Example:"
print(" dump dump, {abc=123, true}, math.sin(1)", "=>")
print(printRet(dump, {abc=123, true}, math.sin(1)))
print "Export: sh.dump(arg)"
return
elseif _cmdline then
printRet(sh.eval(_cmdline))
else -- export
return dump
end