我想一個字符串在Lua添加到返回的值:的Lua:試圖在一個字符串值進行算術
local function func(str)
return (str+"_something")
end
print(func("ABC"))
,我得到一個錯誤:
"attempt to perform arithmetic on local 'str' (a string value)"
或者這個錯誤(在我原來的程序):
@user_script:1: user_script:1: attempt to perform arithmetic on a string value
我試圖用tosring(STR)+ 「_東西」,但沒有幫助...
那麼如何在Lua中串聯一個字符串?
'getmetatable '' .__ add = function(a,b)return a..b end' –
@EgorSkriptunoff,如果字符串包含數字,則不起作用:'「 1「+」2「'是數字'3',而不是字符串'」12「'。 – lhf
@lhf - Ops!忘了這個奇怪的功能。從字符串自動強制轉換爲其他數據類型相當不自然。 –