lua-users home
lua-l archive

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


2014-04-10 8:16 GMT+02:00 Dirk Laurie <dirk.laurie@gmail.com>:
> 2014-04-10 6:50 GMT+02:00 Coroutines <coroutines@gmail.com>:
>
>> After thinking about this for a while I think it would be okay if
>> object literals were also allowed instead of only valid identfiers:
>>
>> 1, 2, 3 in { 'a', 'b', 'c' } --> return 'a', b', 'c'
>
> I'm happier with the notion that `x,y,z in tbl` is just a synonym for
> `tbl.x, tbl.y, tbl.z`. The above would be better described by
> { 'a', 'b', 'c' }[1,2,3] — but let's not hijack this thread.

Suppose that the notation tbl[i,j,k] meant tbl[i],tbl[j],tbl[k], not
as a syntactic sugar, but as genuine multiple indexing overridable
by metamethods.

__index(tbl,key1,key2,...).
__newindex(tbl,key1,val1,key2,val2,...).

Invoked when tbl is not a table, when key1 is absent, and when more
than one key is supplied.

People who want tbl[i,j] to mean matrix-like indexing can do that
by metamethods.