-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfor.lua
65 lines (56 loc) · 1.71 KB
/
for.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
for i=10,1,-1 do
print(i)
end
print("============")
for i=1,10,1 do
print(i)
end
print("============")
data = {"one", "two", "three"}
for i, v in ipairs(data) do
print(i, v)
end
print("============")
data = {aa=1,bb=2,cc=3,dd=4}
for i, v in pairs(data) do
print(i, v)
end
function ptbp (lua_table, indent)
if type(lua_table) ~= 'table' then
print '------------------ptb--------------------\n'
print (lua_table)
print '------------------ptb--------------------\n'
return
end
indent = indent or 0
for k, v in pairs(lua_table) do
if type(k) == "string" then
k = string.format("%q", k)
end
local szSuffix = ""
if type(v) == "table" then
szSuffix = "{"
end
local szPrefix = string.rep(" ", indent)
formatting = szPrefix.."["..k.."]".." = "..szSuffix
if type(v) == "table" then
print(formatting)
ptb:p(v, indent + 1)
print(szPrefix.."},")
else
local szValue = ""
if type(v) == "string" then
szValue = string.format("%q", v)
else
szValue = tostring(v)
end
if type(k) == "number" then
print(szPrefix..szValue..",")
else
print(formatting..szValue..",")
end
end
end
end
local data = {a=1,b=2,c=3,d=4,e=5}
ptbp(data)