有没有办法在 Lua 5.3 中使用 math.pow?

我找到了一篇文章,现在我发现了一个这个非常有用的内置函数的语法错误。我的代码很简单,但错误不是:

print(math.pow(10, 2))

错误: File:2: attempt to call a nil value (field 'pow')

如果 Lua 5.3 中不再存在 math.pow,则我可能必须为实际创建一个新函数。 但我仍然想做一个懒惰的驴子 :)

点赞
用户4515989
用户4515989

math.pow^ 运算符代替:10^2

如果你有很多调用 math.pow 的地方,你可以添加以下函数:

math = math or {}
function math.pow(a, b)
    return a ^ b
end
2020-07-23 09:29:48