lua-users home
lua-l archive

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

> I just wondering what's behind that design decision, I mean what's the pro and cons of having an hash table for globals instead of a simpler array?

I'm not sure what you mean by "simpler array".

If you mean that each global would be given a number and then access to it
would just index an array with that number, then of course the same name
has to be given the same number and that number depends on *when* the global
is created. This would complicate precompiling scripts via luac. (I think
the earliest versions of luac had to solve this problem.)

In any case, you'd still need to find the number given the name and a
hash table is ideal for that.

You might want to read the source of the early versions of Lua and see
how globals are implemented. Get the lua-all package: