forked from Auctionator/Auctionator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuctionatorUtil.lua
executable file
·75 lines (61 loc) · 1.8 KB
/
AuctionatorUtil.lua
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-- https://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/
function Auctionator.Util.Print( t, name )
if not Auctionator.Debug.IsOn() then
return
end
name = name or 'Unknown'
print( '*************** TABLE ' .. name .. ' *****************' )
-- print( 'Util.Print', debugstack( 2, 1, 0 ) )
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
print(indent.."*"..tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)=="table") then
for pos,val in pairs(t) do
if (type(val)=="table") then
print(indent.."["..pos.."] => "..tostring(t).." {")
sub_print_r(val,indent..string.rep(" ",string.len(pos)+2))
print(indent..string.rep(" ",string.len(pos)).."}")
elseif (type(val)=="string") then
print(indent.."["..pos..'] => "'..val..'"')
else
print(indent.."["..pos.."] => "..tostring(val))
end
end
else
print(indent..tostring(t))
end
end
end
if (type(t)=="table") then
print(tostring(t).." {")
sub_print_r(t," ")
print("}")
else
sub_print_r(t," ")
end
print()
end
function Auctionator.Util.FlatPrint( t )
local buffer = {}
for position, value in pairs( t ) do
table.insert( buffer, value )
end
print( [[{]] .. table.concat( buffer, ',' ) .. [[}]] )
end
function Auctionator.Util.UTF8_Truncate( string, options )
options = options or {}
local newLength = options.newLength or 127
if string:len() <= newLength then
return string
end
local position, char;
for position = newLength, 1, -1 do
char = string:byte( position + 1 )
if bit.band( char, 0xC0 ) == 0x80 then
return string:sub( 1, position - 1 )
end
end
end