lua-users home
lua-l archive

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


2014-03-25 5:13 GMT+02:00 Andrew Starks <andrew.starks@trms.com>:

> I also agree that ".." should always call __tostring, even on (especially) tables.

I don't agree. Lua should "not know what to do" so that a metamethod will be
looked for. Otherwise we can chuck away the __concat metamethod.

For example, with a simple "list" object:

a = list{1,2,3}
tostring(a) --> "{1,2,3}"
a..4 --> {1,2,3,4}, not "{1,2,3}4"

Having said that, I must admit that I've often wished for a builtin
Lua function that
simply concatenates all its arguments. It's available in the API and the VM, but
not in Lua. That makes it trivial to write in C for oneself, of course.

/* tuple.concat(...) */
static int tuple_concat(lua_State *L) {
  lua_concat(L,lua_gettop(L));
  return 1;
}

But I find it curious that this powerful Lua feature is not exposed at the level
of the scripting language.