lua-users home
lua-l archive

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


The first change is to remove length entirely.

Lua 5.0 had a concept of table length (setn). Lua 5.1 had a different concept of table length (#). Lua 5.2/5.3 has yet another concept of table length (__len).

Note that they are all different concepts. The best way to solve the length problem is to remove length entirely.

Let the user and the libraries define how length should be handled. If a library wants to add setn, no problem! If a library wants O(n) length based on pairs(), no problem! If a library wants O(n) length based on ipairs(), no problem! If a library wants O(logn) length based on rawget(), no problem! If a library wants O(logn) length based on __index, no problem! This also includes the removal of #, obviously.

Some additional benefits include:

If someone wants to replace the whole stdlib just so they can use 0-based indexing, no problem!

local t = {[0]=1, 2, 3, 4, 5}

print(zerolen(t)) --> 5

The second change is to remove all mentions of table length from the C API. The C API shall not rely on table length, ever. Each C API function should handle length on its own way. (The lack of consistency *is* a consistency in itself.)

I believe these changes will really help w.r.t. arguments about length.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.