16.自带库

16.自带库


16.1 知识点

时间

os.time() 系统时间戳

print(os.time())                                     --1695818702

(os.time({ year = 年, month = 月, day = 日 } 传入时间相关的参数得到时间戳

print(os.time({ year = 2014, month = 8, day = 14 })) --1407988800

os.date("*t") 返回当前时间的表对象

local nowTime = os.date("*t")
for k, v in pairs(nowTime) do
    print(k, v)
    -- hour	20
    -- min	45
    -- wday	4
    -- day	27
    -- month	9
    -- year	2023
    -- sec	2
    -- yday	270
    -- isdst	false
end

数学运算

math.abs(数值) 绝对值

print(math.abs(-1))      -- 1

math.deg(数值) 传入弧度转角度

print(math.deg(math.pi)) -- 180

math.cos(数值) 三角函数 传弧度

print(math.cos(math.pi)) -- -1

math.floor(数值) 向下取整

print(math.floor(2.6))   -- 2

math.ceil(数值) 向上取整

print(math.ceil(5.2))    -- 6

math.max(数值1, 数值2) 最大值

print(math.max(1, 2))    -- 2

math.min(数值1, 数值2) 最小值

print(math.min(4, 5))    -- 4

math.modf(数值) 把数值分离分成整数部分和小数部分并返回

print(math.modf(1.2))    -- 1	0.2

math.pow(底数, 幂) 幂运算

print(math.pow(2, 5))    --32

math.randomseed(任何数值) 设置随机数种子

math.randomseed(os.time())

math.random(最大值) 返回随机数 随机前要设置随机数种子 不然每次随机出来的数都一样

print(math.random(100)) --20 不是随机的 相同的随机数种子每次运行第一次随机出来都相同
print(math.random(100)) --98 随机的

math.sqrt(底数) 开方

print(math.sqrt(4))     --2

路径

package.path lua脚本加载路径

print(package.path)                    -- ;.\?.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
package.path = package.path .. ";C:\\" --可以进行拼接
print(package.path)                    --;.\?.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:\

16.2 知识点代码

print("**********自带库************")


print("**********知识点一 时间************")
--os.time() 得到系统时间戳
print(os.time())                                     --1695818702
--(os.time({ year = 年, month = 月, day = 日 } 传入时间相关的参数得到时间戳
print(os.time({ year = 2014, month = 8, day = 14 })) --1407988800
--os.date("*t")会返回当前时间的表对象
local nowTime = os.date("*t")
for k, v in pairs(nowTime) do
    print(k, v)
    -- hour	20
    -- min	45
    -- wday	4
    -- day	27
    -- month	9
    -- year	2023
    -- sec	2
    -- yday	270
    -- isdst	false
end


print("**********知识点二 数学运算************")
--math.abs(数值) 绝对值
print(math.abs(-1))      -- 1
--math.deg(数值) 传入弧度转角度
print(math.deg(math.pi)) -- 180
--math.cos(数值) 三角函数 传弧度
print(math.cos(math.pi)) -- -1
--math.floor(数值) 向下取整
print(math.floor(2.6))   -- 2
--math.ceil(数值) 向上取整
print(math.ceil(5.2))    -- 6
--math.max(数值1, 数值2) 最大值
print(math.max(1, 2))    -- 2
--math.min(数值1, 数值2) 最小值
print(math.min(4, 5))    -- 4
--math.modf(数值) 把数值分离分成整数部分和小数部分并返回
print(math.modf(1.2))    -- 1	0.2
--math.pow(底数, 幂) 幂运算
print(math.pow(2, 5))    --32
--math.randomseed(任何数值) 设置随机数种子
math.randomseed(os.time())
-- math.random(最大值) 返回随机数 随机前要设置随机数种子 不然每次随机出来的数都一样
print(math.random(100)) --20 不是随机的 相同的随机数种子第一次随机出来都相同
print(math.random(100)) --98 随机的
-- math.sqrt(底数) 开方
print(math.sqrt(4))     --2


print("**********知识点三 路径************")
--package.path lua脚本加载路径
print(package.path)                    -- ;.\?.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
package.path = package.path .. ";C:\\" --可以进行拼接
print(package.path)                    --;.\?.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:\


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 785293209@qq.com

×

喜欢就点赞,疼爱就打赏