本文内容来自Lua官方文档
math.pi 返回pi的值、
math.huge 返回一个最大数
math.abs(x) 返回x的绝对值
il(x) 向上取整
math.floor(x) 向下取整math.fmod(x,y) x/y取模,注意小数
df (x) 取x的整数和小数部分
math.sqrt(x) 返回x的开平方
math.pow(x,y) 返回x的y次幂
p(x) 返回e的x次幂
math.frexp(m) m = x*(2^y),把m拆成x和y两部分
math.ldexp(x,y) 返回x*(2^y)math.random(x,y) 没有参数返回[0,1]之间的数,一个整数参数m返回[1,m]之间的整数
math.randomseed(x) 设置随机数种子
os.time() 返回当前系统时间距离1970年1月1日0秒的秒数,可以传一个参数
os.date() 返回本地化的时间字符串math.deg(x) 弧度转角度
math.rad(x) 角度转弧度
s(x) 返回x的余弦值,结果是弧度
sh(x) 返回双曲线余弦值
math.sin(x) 返回x的正弦值,结果是弧度
math.sinh(x) 返回双曲线正弦值
math.acos(x) 返回x的反余弦值,结果是弧度
math.asin(x) 返回x的反正弦值,结果是弧度
math.atan(x) 返回x的反正切值,结果是弧度
math.atan(y,x) 返回y/x的反正切值,结果是弧度,x是0也会正确处理
string.len(str) 返回str的长度
string.lower(str) string.upper(str) 把str转化为小写|大写
string.byte() str:byte(1,3) 返回字符串str中从第1位到第3位的ASCII值
string.char() string:char(49,50,51) 返回ASCII值对应的字符串
string.dump(function) 返回指定函数的二进制代码(函数必须是一个Lua函数,并且没有上值)string.find(s, pattern [,init [,plain]])
string.find(s,"abcd",1,plain) 查找s中首次出现"ab"的位置,从1位置开始,如果找到则返回首次出现的起始和结束位置(1,4)否则返回nilstring.format(formatstring,...) 格式化字符串
string.format('%s', 'a string with "quotes" and n new t line')
结果:
a string with "quotes" and
new line
%q:为自动将对应参数字串中的特殊字符加上string.match(s,pattern,init) 查找s中从init开始是否有pattern,如果有则返回pattern
atch(s,pattern) 返回一个迭代函数,每次调用此函数,将返回下一个查找到的样式串对应的字符
s = "hello world from Lua"
for w atch(s, "%a+") doprint(w)
end
结果:
hello
world
from
Luastring.sub(s, i [,j]) 字符串截取i位置和j位置之间的字符串
string.gsub(s, pat, repl [,n]) 将字符串中的pat替换为repl,返回字符串及替换的次数
p(s, n) 把字符串s重复n次
verse(s) 返回s的反转
本文发布于:2024-02-05 01:40:59,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170721129361862.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |