lua报错代码实例:
local k= 'text="123sdf圣达菲s | 1232" asdf'
local a = {}
print(k:gsub("123",""))
table.insert(a,k:gsub("123",""))
text="sdf圣达菲s | 2" asdf 2
bad argument #2 to 'table' (number expected, got string)
原因在于,lua的table.insert 本来接收3个参数, table,pos,content
其中,pos可以省略,默认追加到table结尾
而我们gsub时候,实际上是返回了2个参数,所以insert时候被当作传入了3个参数,因此报错
因此要多加个括号,如下
table.insert(a, k:gsub("123","") )
修改为
table.insert(a, ( k:gsub("123","") ) )