Suppose I insert a row into a table as follows:
table.insert(tbl, mystring)
and that mystringis created by replacing all occurrences of "a" with "b" in input:
mystring = string.gsub(input, "a", "b")
The obvious way to combine two into one statement does not work, because it gsubreturns two results:
table.insert(tbl, string.gsub(input, "a", "b")) -- error!
-- (second result of gsub is passed into table.insert)
which, I believe, is the price paid to support multiple return values. The question is, is there a standard built-in way to select only the first return value? When I found select, I thought that this is exactly what he did, but, alas, he actually selects all the results from N and onwards, so this does not help.
, select :
function select1(n, ...)
return arg[n]
end
table.insert(tbl, select1(1, string.gsub(input, "a", "b")))
, .
, - ? , Lua select1 ?