--这是Lua的语句
print("hello lua")
--[[
这个是多行注释的区域
Lua变量类型
1.数字类型
2.字符串类型
3.thread类型 线程
4.function 函数
5.table 唯一的数组融合了链表和键值对
6.其他类型
]]
--把多行注释两个横杆去掉,就变成多行文本输出
text=[[
chang wen ben
heng jian dan
]]
print(text)
a = function( var )
print("user input is "..var)
end
a("I'm A")
--table唯一使用大括号的地方
myTable = {
12,
13
}
--输出table的方法
for k,v in pairs(myTable) do
print(k,v)
end
--[[
输出的结果
1 12
2 13
]]
--如果一个函数function函数中创建的变量也是global(没有使用local关键字),那么也意味着它是全局变量
b = "123" --是全局类型,其他文件引用
local c = 12 --是一个private类型,不能被其他文件访问到
--[[
Lua中的条件判断语句
1 条件判断的特殊符号组合 == > < >= <= ~=不等于
2没有()then elseif连一起 也没有switch语句
]]
local a =12
if a == 12 then
print("a's value is 12")
end
if a==11 then
print("value is 11")
elseif a ~= 11 then --!=是~=
print("value is not 11")
end
--完整的 if else 语句块
if a==2 then
print("value is 2")
elseif a==11 then
print("value is 11")
else
print("value is "..a)
end
--[[
Lua中的函数
]]
--无参函数
local function myfunc01()
print("im myfunc01")
end
--调用函数 无参数的
myfunc01()
--有参函数
local function myfunc02(a)
print (a)
end
myfunc02("im ok")
--有参数 也有返回值的参数
local function myfunc03(a)
return a
end
print(myfunc03("im im"))
--可以返回多返回值,并接收 Lua的特性
local function myfunc04()
return 1,2
end
local a,b = myfunc04()
print(a)
print(b)
--函数里面可以传递 参数...可变
local function myfunc05(...)
local mtable = {...}
--遍历
for k,v in pairs(mtable) do
print(k,v)
end
end
myfunc05("12",123,"ok")
--[[myfunc05输出的结果 table是从1开始mtable[1]
1 12
2 123
3 ok
]]
--[[
Lua中的循环语句
while语句
do while lua中是repeat until
for语句
在lua中没有加加操作符
]]
--while
mtable={1,2,3}
local index=1
while mtable[index]