function msg(...)
print(arg[1], arg[10])
print(1, 2, false and 3, 5)
end
msg(12,52,25,21)
--结果是12, nil 1,2,false,5
function msg(...)
for i, j in pairs({...}) do
print(i, j)
end
end
msg(10,20,30)
--[[
1 10
2 20
3 30
]]--
tt ={
1,2,3,
["20"] = "200",
Age = 20 ,
["Age"] = 30,
ddr =
{
test = 1,
test2 = 3
}
}
tt.JOne = {Gender = "男", age = "28"}
print(type(tt["20"]).."10".."\n"..tt["JOne"]["Gender"])
print(tt.Age)
local a = 3 and 4 or 5;
print(5%3)
--[[注释]]--
while a > 0
do
print(a, not(a~=b))
a = a - 1
end
for c=2, 5, 0.5
do
print(c)
end
print((c or 1).."\f")
html = [[
<html>
<head>
<title>testPage</title>
</head>
<body>
something
</body>
</html>
]]
print(html)
--可返回多结果
function s()
return 2, 3, 4
end
print(s())
--面向对象
t =
{
age = 13,
gender = "male",
add = function(sel, n)
return sel.age + n
end
}
print(t.add(t, 12))
print(t:add(12)) -- 与上面一个函数等价 t:function(data) <==> t.function(t, data)
a,b,c = 1, 2, 3
if a > b then
print(a)
elseif a > c then
print(b)
else
print(c)
end
repeat
print(c)
c = c - 1
until c ~= 2
请发表评论