- 打卡等级:本地老炮
- 打卡总天数:377
- 打卡月天数:25
- 打卡总奖励:375
- 最近打卡:2025-12-25 08:50:09
|
插件介绍:https://waylee.net/thread-3530-1-1.html
Lua5 向下兼容 Lua4 函数表如下
Lua 数学函数对照表
| 函数名 |
功能说明 |
Lua 5 对应调用 |
abs(x) |
取绝对值 |
math.abs(x) |
sin(x) |
正弦(参数为弧度) |
math.sin(x) |
cos(x) |
余弦(参数为弧度) |
math.cos(x) |
tan(x) |
正切 |
math.tan(x) |
asin(x) |
反正弦(结果为弧度) |
math.asin(x) |
acos(x) |
反余弦(结果为弧度) |
math.acos(x) |
atan(x) |
反正切(结果为弧度) |
math.atan(x) |
atan2(y, x) |
反正切(带象限判断) |
math.atan2(y, x) |
ceil(x) |
向上取整 |
math.ceil(x) |
floor(x) |
向下取整 |
math.floor(x) |
mod(x, y) |
取模(余数) |
math.fmod(x, y)(Lua5改名) |
frexp(x) |
分解浮点数为尾数和指数 |
math.frexp(x) |
ldexp(m, e) |
计算 m * 2^e |
math.ldexp(m, e) |
sqrt(x) |
平方根 |
math.sqrt(x) |
min(x, y, ...) |
返回最小值 |
math.min(x, y, ...) |
max(x, y, ...) |
返回最大值 |
math.max(x, y, ...) |
log(x) |
自然对数 ln(x) |
math.log(x) |
log10(x) |
常用对数 log₁₀(x) |
math.log10(x)(Lua5可用 math.log(x,10)) |
exp(x) |
e 的 x 次方 |
math.exp(x) |
deg(x) |
弧度 → 角度 |
math.deg(x) |
rad(x) |
角度 → 弧度 |
math.rad(x) |
pow(x, y) |
幂运算 x^y |
math.pow(x, y) 或 x^y |
random() |
随机数 (0,1) |
math.random() |
random(n) |
随机整数 [1, n] |
math.random(n) |
random(m, n) |
随机整数 [m, n] |
math.random(m, n) |
randomseed(x) |
设置随机种子 |
math.randomseed(x) |
字符串库
| 函数名 |
功能说明 |
Lua 5 对应调用 |
strlen(s) |
返回字符串长度 |
string.len(s) |
strsub(s, i, j) |
截取字符串从第 i 到 j 个字符 |
string.sub(s, i, j) |
strlower(s) |
转小写 |
string.lower(s) |
strupper(s) |
转大写 |
string.upper(s) |
strchar(n1, n2, ...) |
将数字转为对应 ASCII 字符 |
string.char(n1, n2, ...) |
strrep(s, n) |
字符串重复 n 次 |
string.rep(s, n) |
ascii(s [, i]) |
返回字符串第 i 个字符的 ASCII 值(旧名) |
string.byte(s [, i]) |
strbyte(s [, i]) |
返回字符串第 i 个字符的 ASCII 值 |
string.byte(s [, i]) |
format(fmt, ...) |
字符串格式化 |
string.format(fmt, ...) |
strfind(s, pattern [, init]) |
查找子串或模式位置 |
string.find(s, pattern [, init]) |
gsub(s, pattern, repl [, n]) |
全局替换字符串 |
string.gsub(s, pattern, repl [, n]) |
表库
| 函数名 |
功能说明 |
Lua 5 对应调用 |
foreach(t, f) |
遍历表中所有键值,对每个 (k, v) 调用 f(k, v);若 f 返回非 nil 则中止并返回该值 |
(无直接对应)用 pairs:for k,v in pairs(t) do local r=f(k,v); if r~=nil then return r end end |
foreachi(t, f) |
按整数索引 1..n 遍历数组部分,对每个 (i, v) 调用 f(i, v);若 f 返回非 nil 则中止并返回该值 |
(无直接对应)用 ipairs:for i,v in ipairs(t) do local r=f(i,v); if r~=nil then return r end end |
getn(t) |
获取数组长度(连续整数索引部分的长度) |
table.getn(t) |
insert(t [, pos], value) |
在表尾或指定位置插入元素 |
table.insert(t [, pos], value) |
remove(t [, pos]) |
删除并返回指定位置的元素(默认最后一个) |
table.remove(t [, pos]) |
sort(t [, comp]) |
对数组部分排序,可选比较函数 comp(a,b) |
table.sort(t [, comp]) |
table.foreachi(t, function(i, v)
PushDebugMessage( v)
end)
|
|