lua-users home
lua-l archive

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


On Wed, Sep 8, 2010 at 9:33 AM, Jerome Vuarand <jerome.vuarand@gmail.com> wrote:
> >From a user point of view, that would seem weird to change the key
> type.

not so weird for a javascript user:

Rhino 1.7 release 2 2010 01 20
js> a={}
[object Object]
js> a[100]=5
5
js> for (k in a) { print (k, typeof(k)); }
100 string


but absolutely unacceptable for Lua users.

quick and fallible array/object test:

function isarray(t)
    return type(t)=='table' and (next(t))==1 and (next(t,#t))==nil
end

this depends on the common case where an array-like table is contained
in the array part of the table, and also that the current
implementation of next() searches first on the array part, and then on
the hash part.

-- 
Javier