print(“hello,world”)
print(“hello,world”)
..可以用来做字符串组拼;使用#来运算字符串的长度
table
print(type(type))
返回function
print(type(x))
变量x未定义类型,返回nil
mytable={"lua","c","c++","c#"}
mymetatable={
__add=function (tab,newtable)
local mi=0
for k,v in pairs(tab) do
if(k>mi) then
mi=k
end
end
for k,v in pairs(newtable) do
mi=mi+1
table.insert(tab,mi,v)
end
return tab
end
}
mytable = setmetatable(mytable,mymetatable)
newtable = {"java","boo","php"}
for k,v in pairs(mytable) do
print("相加之前立刻输出mytable:"..k,v)
end
print(".....................................")
for k,v in pairs(newtable) do
print("相加之前立刻输出newtable:"..k,v)
end
print(".....................................")
num=newtable+mytable --newtable自身基础之上加mytable
fun=mytable+newtable -- mytable在自身基础之上再加newtable(等同于mytable+newtable+mytable)
for k,v in pairs(newtable) do
print("相加时立刻输出newtable:"..k,v)
end
print(".....................................")
for k,v in pairs(mytable) do
print("相加时立刻输出mytable:"..k,v)
end
print(".....................................")
for k,v in pairs(num) do
print("相加完之后立刻输出num:"..k,v)
end
print(".....................................")
for k,v in pairs(fun) do
print("相加完之后立刻输出fun:"..k,v)
end
print('Hallo World')
数据类型
nil
boolean
number
string
function
userdata
thread
table
86287741427927965502054627678583973344898412197872091167350662069171495015305911796757360434110987930924242177307916832278861619
782459
【漂亮
Function add(num1,num2,func)
res = num1 + num2
func(res)
end
printfunc = Function (res)
print(res)
end
add(40,50,printfunc)
for k,v in pairs(tab) do
end
while a<7 do
end
a = 1
repeat
print(a)
a=a+1
until(a>10)
输出了1-10
number
if then
else
lua的多变量赋值真心好用
print("Hello world")
多练
区分大小写的
print(type(2))
print(type(2.2))
print(type(true))----boolean
print(type(nil)) ----nil
if true then
print(true)
end
if nil then
print("nil被当做true处理")
end
if nil then
print("nil被当做true处理")
else
print("nil被当做false处理")
end
1.注释:
--[[
aaaa
--]]
2.nil用法
table= {key1 = "aa", key2 = "bb" }
print(table.key1)
table.key1 = nil
table = nil