lua解析器从5.1升到5.3之后有脚本处理需要注意的事项

lua解析器从5.1升到5.3之后有脚本种有两处需要注意
一.可变参数的写法变动

5.3的版本引用可变参数的时候不能直接使用arg对可变参数进行引用,需要显示申明一个表local arg={ … }之后再引用arg,如果对外传可直接用 … 传递可变参数

用例说明:

1
2
3
4
5
6
7
8
9
local function printarg( ... )
local arg={ ... }

log.info("print arg",#arg,arg[1],arg[2],arg[3])
end

local function testarg( ... )
printarg( ... )
end

运行testarg(1111,2222,3333)的结果如下:

[print arg] 3 1111 2222 3333

二.不再区分float跟非float

不在区分float跟非float,如果需要整形,可以直接调用math.floor取整

用例说明:

1
2
3
4
5
6
7
8
9
local function testmath()
local aa = 8
local bb = 3/2
local cc=3%2

log.info("type",math.type(aa),math.type(bb),math.type(cc))
log.info("value",aa,bb,cc)
log.info("to int",math.floor(aa),math.floor(bb),math.floor(cc))
end

运行testmath()的结果如下:

[type] integer float integer
[value] 8 1.5 1
[to int] 8 1 1

上次更新 2021-01-28