更新时间:2023-02-03 08:59:39
tonumber
只能用于实数字符串,不能用于算术表达式.
tonumber
can be used only on a string that is a real number, not an arithmetic expression.
您可以加载字符串并运行它:
You can load the string and run it:
x = "5 + 5"
func = assert(load("return " .. x))
y = func()
print(y)
在 Lua 5.1 中,使用 loadstring
而不是 load
.
In Lua 5.1, use loadstring
instead of load
.