--自带库
--string
--table
--时间
print(os.time())--1601168290
print(os.time({year=2020,month=9,day=25}))--1601006400
--os.date("*t")传回来的是张表
local now=os.date("*t")
print(now)--table: 0x7fa99f604360
for k,v in pairs(now) do
print(k,v)
end
--[[
month 9
hour 9
yday 271
isdst false
year 2020
day 27
min 5
wday 1
sec 8
]]
--打印的是这个
print(now.hour)--9
--数学运算
--绝对值
print(math.abs(-11))--11
--弧度转角度
print(math.deg(math.pi))--180
--三角函数,参数是弧度
print(math.cos(math.pi))-- -1.0
--向下向上取整
print(math.floor(1.3))--1
print(math.ceil(1.3))--2
--最大最小值
print(math.max(1,3))--3
print(math.min(1,3))--1
--分别打印整数和小数部分,小数分离
print(math.modf(1.3))--1 0.3
--幂 pow
print(math.pow(3,3))--27.0
--随机数 先设置随机数种子
math.randomseed(os.time())--随机数种子
print(math.random(100))--29 7 13 每次运行不一样
print(math.random(100))--83 45 77 每次运行不一样
--开方
print(math.sqrt(9))--3.0
--路径
--lua脚本加载路径
print(package.path)
--[[/usr/local/share/lua/5.3/?.lua;/usr/local/share/lua/5.3/?/init.lua;/usr/local/lib/lua/5.3/?.lua;/usr/local/lib/lua/5.3/?/init.lua;./?.lua;./?/init.lua]]
--每条路径用分号隔开
package.path=package.path..";".."mypackage:\\"--会在之前的路径基础上加luamypackage:\
print(package.path)
--要了解更多的库可以遍历_G