lua-users home
lua-l archive

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

Forgive me if this has been mentioned before (I couldn't find anything
on it in the archives):

Would it be possible to have a fifth optional parameter to
table.concat to have it use a passed function on values that are not
strings or numbers, to return strings.


> t = {n = 6, "hi", 5, nil, 4, function() end, { }}
> print(table.concat(t, " ", 1, t.n, tostring))
hi 5 nil 4 function: kdjfjdf, table: kjdfkjdf

Something like that, but could also allow for more complex actions
such as a table containing many tables containing strings to be
concatenated, or calling functions that return other strings to be

I realize table.concat uses nil as a flag for the end of the array, so
perhaps the function is only valid when specific indices are given.
(as that's the only way the function could be passed anyway).

-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant