forked from yuanfengyun/q_algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.lua
More file actions
50 lines (45 loc) · 1.21 KB
/
utils.lua
File metadata and controls
50 lines (45 loc) · 1.21 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
local M = {}
local function serialize(obj)
local lua = ""
local t = type(obj)
if t == "number" then
lua = lua .. obj
elseif t == "boolean" then
lua = lua .. tostring(obj)
elseif t == "string" then
lua = lua .. string.format("%q", obj)
elseif t == "table" then
lua = lua .. "{"
for k, v in pairs(obj) do
lua = lua .. "[" .. serialize(k) .. "]=" .. serialize(v) .. ","
end
local metatable = getmetatable(obj)
if metatable ~= nil and type(metatable.__index) == "table" then
for k, v in pairs(metatable.__index) do
lua = lua .. "[" .. serialize(k) .. "]=" .. serialize(v) .. ","
end
end
lua = lua .. "}"
elseif t == "nil" then
return "nil"
elseif t == "userdata" then
return "userdata"
elseif t == "function" then
return "function"
elseif t == "thread" then
return "thread"
else
error("can not serialize a " .. t .. " type.")
end
return lua
end
M.table_2_str = serialize
function M.print(o)
print(serialize(o))
end
function M.get_card_str(i)
if i <= 9 then
return i.."万"
end
end
return M