Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua: attempt to perform arithmetic on a string value

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 ?

like image 565
Aviram Netanel Avatar asked Jan 26 '14 10:01

Aviram Netanel


1 Answers

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

like image 86
Aviram Netanel Avatar answered Nov 02 '22 09:11

Aviram Netanel