lua-users home
lua-l archive

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


2015-03-26 23:15 GMT+02:00 Andrew Starks <andrew.starks@trms.com>:

> Here, I that I wish that concat would use tostring on all non-string
> value types that do not have metamethods, instead of erroring. At the
> same time, dropping support for `__concat` would seem reasonable.

At present, Lua has:

1. table.concat

This works by building up a luaL_Buffer and does not respect
__concat or __tostring. It is designed to concatene strings only.
The fact that numbers are acceptable is a side effect of the fact
that they are acceptable to lua_tostring.

2. lua_concat

This concatenates a specified number of items on the stack and
respects __concat. It is not exposed at the Lua level, but it is very
easy to implement via the API; I save it as string.concat. It is an
immensely powerful function when used together with a __concat
metamethod for strings, so powerful that I set and unset that
metamethod locally every time I use it.

3. CONCAT VM instruction

This also respects __concat but does not call lua_concat.