Unity之热更新:(二)Lua

一、Lua保留关键词释义

local :加在变量名前表示局部变量

nil:表示一个无效值,未初始化的变量默认为nil,如果你想删除一个变量,只需要赋值为nil。在条件表达式中相当于false。

and、or、not:逻辑运算符

true、false:boolean类型。除了false和nil,其他都是true。

if、then、elseif、else、end

a=60
if(a>=80) then
    print("Good")
elseif (a>=60) then
    print("OK")
else
    print("Bad")
end

while、do

while(true) do
    print("*")
end

for、in:

goto、break:循环控制语句

function、return:函数,可以有多个返回值,可以接受可变数目的参数(...)

repeat、until

a=1
repeat
    print(a)
    a=a+1
until(a>5)

注释-- 单行注释 --[[ ]] 多行注释

其他运算符:..连接字符串  #返回字符串长度

二、八种数据类型

nil 无效值 对于全局变量和table,nil还有“删除”作用
boolean 布尔型 falsenil是false,其他都是true
number 双精度浮点数 Lua只有一种数字类型double
string 字符串 可用双引号、单引号、方括号表示 html=[[<html></html>]]
function 函数 Lua里函数可以存在变量里
userdata 自定义类型  可以将C/C++的数据存储到Lua变量中调用
thread 线程 Lua里主要的线程是协同程序coroutine
table Lua里初始索引从1开始,表的索引可以是数字或字符串,表是可变长度的

 

三、字符串

四、table

1. table 连接

2.  插入、移除、排序

3. 遍历

 五、标准库

1. 数学运算函数

math.abs math.max math.min math.mod math.pow math.sqrt
math.sin math.cos math.tan math.asin math.acos math.atan
math.atan2 math.rad math.ceil math.floor math.deg math.exp
math.frecp math.ldexp math.log math.log10 math.random math.randomseed

 

2. 字符和数字转换

 3. loadstring 和 assert

 4. dofile(filename)

 5. rawequal、rawget、rawset

 

posted @ 2021-12-08 16:29  番茄玛丽  阅读(159)  评论(0编辑  收藏  举报