更新时间:2023-02-03 08:33:30
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
.