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
|
--[[
Extensions that don't belong anywhere else
]]
-- Override tostring to display more info about the table
local old_tostring = tostring
local numtabs = 0
local printed_tables = {}
function tostring(el)
if type(el) == "table" and printed_tables[el] == nil then
printed_tables[el] = true
numtabs = numtabs + 1
local strbuilder = {"{"}
for k,v in pairs(el) do
strbuilder[#strbuilder + 1] = string.format("%s%s : %s", string.rep("\t",numtabs), tostring(k), tostring(v))
end
printed_tables[el] = nil
strbuilder[#strbuilder + 1] = string.rep("\t",numtabs - 1) .. "}"
numtabs = numtabs - 1
return table.concat(strbuilder,"\n")
end
return old_tostring(el)
end
--functions to save my hand
function assertf(bool,msg,...)
if not bool then
error(string.format(msg,...),2)
end
end
function errorf(fmt,...)
error(string.format(fmt,...),2)
end
function printf(fmt,...)
print(string.format(fmt,...))
end
|