helper.lua
1.47 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
61
62
63
--[[
@Author : Mr.wang
@Date : 2016-04-25 09:25:06
@Content : helper
--]]
local cc = cc
local _tostring = tostring
local type, tonumber, table, string = type, tonumber, table, string
local helper = {}
setfenv(1, helper)
function tostring(value)
local str = ''
if (type(value) ~= 'table') then
if (type(value) == 'string') then
str = string.format("%q", value)
else
str = _tostring(value)
end
else
local auxTable = {}
table.foreach(value, function(i, v)
if (tonumber(i) ~= i) then
table.insert(auxTable, i)
else
table.insert(auxTable, tostring(i))
end
end)
table.sort(auxTable)
str = str..'{'
local separator = ""
local entry = ""
table.foreachi (auxTable, function (i, fieldName)
if ((tonumber(fieldName)) and (tonumber(fieldName) > 0)) then
entry = tostring(value[tonumber(fieldName)])
else
entry = fieldName.." = "..tostring(value[fieldName])
end
str = str..separator..entry
separator = ", "
end)
str = str..'}'
end
return str
end
function format(e)
if type(e) ~= "string" then
e = tostring(e)
end
return e
end
function isWindows()
local platform = cc.Application:getInstance():getTargetPlatform()
return platform == cc.PLATFORM_OS_WINDOWS
end
return helper