lua-users home
lua-l archive

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

On Sun, Jun 15, 2014 at 5:49 PM, Tim Hill <> wrote:

On Jun 15, 2014, at 1:15 PM, Andrew Starks <> wrote:

> This is stating something that is very obvious to you guys, but upon thinking about it, the distinction between the *table* library and a
> non-existent library that works with tables + their defined behaviors, aka "objects", becomes important. The same holds for theath library, which also does not work with anything except numbers (or strings that can be numberfied).
> Assuming nothing about Lua were to change, I would find it clarifying, if I haven't missed something that is already present, if there was something that emphasized that distinction:
> "Except for a few exceptions, Lua's standard libraries work with Lua's basic types and do not check for a metatable or metamethods, when manipulating or accessing them."
> Another sentence or three on why this is the case and how these libraries may be built upon to handle "object-like" values, would be good, too.
> What is obvious to the designer or to the CSCI degree holder can look confusing and inconsistent to someone without mental access to the broader issues.
> -Andrew

Yes, you are quite right that this is a part of the problem. On the one hand, tables are just the Lua basic collection type. On the other, they are abstracted via metamethods to form one (common) way to realize OO type behaviors. This slightly schizophrenic model means that table.sort() gets caught in the middle. If we view table.sort() as a fast way to sort data, then raw get/set makes sense. If we view it as a generic function that sorts anything that has numeric indexing and a length, then it needs to use metamethods. In fact, in this model, table.sort() could apply to userdata as well, and probably doesn’t really belong in the table library at all. I’m not saying this is good (it probably isn’t), but the current design does make Lua a little inconsistent, and perhaps generates surprise when people are learning the language, as per the OP.


This is the kind of reason I feel like the table library could be split/renamed to an array library.

Sent from my Game Boy.