Lua基础语法

Lua基础

1.数据类型

boolean——布尔;

number——整型浮点型;

nil——null;

string——字符串;

function——函数(既可以函数声明关键字,也可以当委托使用);

userdata——之后单独分析;

thread——线程;

table——表(索引从1开始);

metatable——元表;

2.变量

loacl——局部变量;

...——字符串拼接(不能使用+号,+会将字符串转为number在相加);

type()——typeof();

3.循环

while(condition)
do
   statements
end

for var= start,last,step do  
    <执行体>  
end  

//do while()
repeat
   statements
until( condition )

4.流程控制

if (condition) then
	statements
end

if (condition1) then
    statements
else if(condition2) then
    statements
else
    statements
end
    
if(condtion) then
   	if(condition2) then
   		statements
    end
end

5.迭代器

table t = {1,2,3,4,5}
for k, v in pairs(t) do
    print(k, v)
end
posted @ 2021-10-08 17:53  小紫苏  阅读(61)  评论(0编辑  收藏  举报