lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello, a question about string.gsub and returned values..

If I do:

io.write(string.gsub("Concatenation, Catharsis, Popocatapetl\n","cat","dog"))

I get the count appened to the output, whereas to get the string only, I'd have to do this:

local X=string.gsub("Concatenation, Catharsis, Popocatapetl\n","cat","dog")
io.write(X)

Thing is, might it not be better to have this the other way round, so that we don't need to make a variable if we don't want to re-use the output? That way we only need introduce extra complexity at need, by using local X,Y=string.gsub(...) when we want the match count.

(One of the things I liked in Lua4 was the X,Y=Y,X method of swapping without making an intermediate variable, yet now we have to make one where we once did not, it seems..) 

I ask this not because I'm too lazy to put up with it; I'm not.. :) I ask because an informed answer might go a long way toward helping me with Lua5.