lua-users home
lua-l archive

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

From: "Ben Cooley" <>
Sent: Wednesday, April 18, 2001 2:03 AM
> > Has anyone done a non-hash array implementation for the Lua 4.0
> > Something on the order of (I'm making up syntax):
> >
> > array myArray[10]  -- All 10 elements set to nil by default
> > myArray[10] = 5      -- Array index 10 becomes the number 5.
> >
> > I know that using the [] for array access would be ambiguous... is it a
> > table or an array?  But for the sake of this example, please bear with
> If you look at the table implementation in lua, you'll be pleasantly
> suprised to discover that for numeric indexes, it actually is an array (it
> doesn't use hash values because it can't).  It's really amazingly clever.

I did look at the table implementation in Lua.  lua_rawgeti() calls
luaH_getnum().  luaH_getnum() sure looks like it accesses a hash table to
me, complete with a hash on the index being requested and a run of the
bucket's linked list checking for a number type and then checking if the key

Author, Workspace Whiz! - A Visual Studio Add-in