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)+"_something" 但没有帮助...

那么在 Lua 中如何连接字符串?

点赞
用户3027111
用户3027111

请见此链接中的“拼接”。

解决方案是使用 ..,比如下面这个例子:

local function func(str)
   return (str.." WORLD")
end

print(func("HELLO"))

它应该返回:

HELLO WORLD

2014-01-26 10:39:19