Question

I'm trying to add a string to a returned value in lua:

local function func(str)
   return (str+"_something")
end

print(func("ABC"))

and I'm getting an error:

"attempt to perform arithmetic on local 'str' (a string value)"

or this error (in my original program):

@user_script:1: user_script:1: attempt to perform arithmetic on a string value

I tried to use tosring(str)+"_something" but didn't help...

so how to Concatenate a string in Lua ?

Was it helpful?

Solution

see "Concatenation" in this link: http://lua-users.org/wiki/StringsTutorial

The solution is to use the .., as in example:

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

print(func("HELLO"))

that's should return:

HELLO WORLD

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top