8. 常用自带库
print("**********自带库************")
--string
--table
print("**********时间************")
--系统时间
print(os.time())
--自己传入参数 得到时间
print(os.time({year = 2014, month = 8, day = 14}))
--获取当前系统规则的时间
--os.date("*t")
local nowTime = os.date("*t")
for k,v in pairs(nowTime) do
print(k,v)
end
print(nowTime.hour)
print("**********数学运算************")
--math
--绝对值
print(math.abs(-11))
--弧度转角度
print(math.deg(math.pi))
--三角函数 传弧度
print(math.cos(math.pi))
--向下向上取整
print(math.floor(2.6))
print(math.ceil(5.2))
--最大最小值
print(math.max(1,2))
print(math.min(4,5))
--小数分离 分成整数部分和小数部分
print(math.modf(1.2))
--幂运算
print(math.pow(2, 5))
--随机数
--先设置随机数种子 如果种子一致 两次随机的结果会一样
math.randomseed(os.time())
print(math.random(100))
print(math.random(100))
--开方
print(math.sqrt(4))
print("**********路径************")
--lua脚本加载路径 多个路径使用;分隔
print(package.path)
package.path = package.path .. ";C:\\"
print(package.path)
for k,v in pairs(_G) do
print(k,v)
end
--io输出:
**********自带库************
**********时间************
1749049211
1407988800
hour 23
min 0
wday 4
day 4
month 6
year 2025
sec 11
yday 155
isdst false
23
**********数学运算************
11
180
-1
2
6
2
4
1 0.2
32
100
25
2
**********路径************
;.\?.lua;C:\Program Files (x86)\Lua\5.1\lua\?.lua;C:\Program Files (x86)\Lua\5.1\lua\?\init.lua;C:\Program Files (x86)\Lua\5.1\?.lua;C:\Program Files (x86)\Lua\5.1\?\init.lua;C:\Program Files (x86)\Lua\5.1\lua\?.luac
;.\?.lua;C:\Program Files (x86)\Lua\5.1\lua\?.lua;C:\Program Files (x86)\Lua\5.1\lua\?\init.lua;C:\Program Files (x86)\Lua\5.1\?.lua;C:\Program Files (x86)\Lua\5.1\?\init.lua;C:\Program Files (x86)\Lua\5.1\lua\?.luac;C:\
string table: 00BAA3A8
xpcall function: 00BA82E8
package table: 00BA23C0
tostring function: 00BA80A8
print function: 00BA8388
os table: 00BAA3D0
unpack function: 00BA8068
require function: 00BA8EE0
getfenv function: 00BA8348
setmetatable function: 00BA81C8
next function: 00BA85E8
assert function: 00BA1C48
tonumber function: 00BA8168
io table: 00BAA600
rawequal function: 00BA83A8
collectgarbage function: 00BA8488
arg table: 00BAA5B0
getmetatable function: 00BA84E8
module function: 00BA8E40
rawset function: 00BA8648
math table: 00BAA330
debug table: 00BAA448
pcall function: 00BA8368
table table: 00BA2668
newproxy function: 00BA0550
type function: 00BA80C8
coroutine table: 00BA2500
_G table: 00BA4F20
select function: 00BA86E8
gcinfo function: 00BA8528
pairs function: 00BA0520
rawget function: 00BA8448
loadstring function: 00BA8688
ipairs function: 00BA4F48
_VERSION Lua 5.1
dofile function: 00BA86A8
setfenv function: 00BA8468
load function: 00BA84A8
error function: 00BA8428
loadfile function: 00BA85A8Lua常用自带库摘要:
- 时间库(os):获取系统时间、自定义时间参数、格式化日期表(包含年、月、日等字段)。
- 数学库(math):提供绝对值、三角函数、取整、最大/最小值、幂运算、随机数(需设置种子)、开方等功能。
- 路径管理(package):支持修改Lua脚本加载路径(多路径用分号分隔)。
- 全局表(_G):可遍历查看所有全局变量和函数。
- 其他库:包括字符串(string)、表格(table)、IO操作(io)等基础功能。
关键示例:时间戳转换、随机数生成、数学运算及路径配置方法。

1 条评论
果博东方客服开户联系方式【182-8836-2750—】?薇- cxs20250806】
果博东方公司客服电话联系方式【182-8836-2750—】?薇- cxs20250806】
果博东方开户流程【182-8836-2750—】?薇- cxs20250806】
果博东方客服怎么联系【182-8836-2750—】?薇- cxs20250806】