math.random()
开箱即用,但如果我将 math
设置为其他内容,它就会中断
local math = 1 + 1 -- 将数学设置为其他值
math.random() -- 中断
有没有办法让 math.random()
在设置 local math = 1 + 1
时仍然有效?
我有一堆带有点表示法函数的模块,例如 coord.get()
或 offset.get()
但是像 coord
和 offset
这样的基本词就无法用于变量名,这很烦人
最佳答案
您始终可以再次请求该模块:
require("math").random()
由于模块已经加载,所以这并不是很昂贵。
关于design-patterns - 如何使用变量名称而不覆盖模块名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57113247/