我在Lua這個簡單的腳本:Lua的錯誤「試圖對字符串值執行算術」
local function addDigits(n)
n=n..""
local s1=0
for i=1,n:len() do
s1=s1+n:sub(i,i)
end
return s1
end
如果我把它叫做小值,
addDigits(12345678123456)
它表現良好。但如果我用較大的值調用它,如
addDigits(1234567812345678)
我收到「嘗試對字符串值執行算術運算」。
我試過用「toNumber」,
s1=s1+tonumber(n:sub(i,i))
,但我收到「試圖在零值進行算術」。
我對Lua很新,所以任何幫助都會很棒!謝謝!
查看http://stackoverflow.com/questions/945731/what-is-the-maximum-value-of-a-number-in-lua –
在這裏用Lua工作得很好5.3.3 –
我使用Windows,並且我發現的最新版本是Lua 5.1 –