Lua:尝试对字符串值执行算术运算 [英] Lua: attempt to perform arithmetic on a string value

查看:887
本文介绍了Lua:尝试对字符串值执行算术运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将字符串添加到lua的返回值中:

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

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

print(func("ABC"))

我得到一个错误:

试图对本地'str'(字符串值)执行算术""

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

或此错误(在我的原始程序中):

or this error (in my original program):

@user_script:1:user_script:1:尝试对字符串值执行算术

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

我尝试使用tosring(str)+"_ something",但没有帮助...

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

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

so how to Concatenate a string in Lua ?

推荐答案

请参见此链接中的串联" : 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"))

应该返回:

HELLO WORLD

HELLO WORLD

这篇关于Lua:尝试对字符串值执行算术运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆