lua-users home
lua-l archive

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


David Given wrote:
They actually work by totally different mechanisms. Lua locals are
lexically scoped true variables, and exist on the Lua stack[1]
internally. When you access a local, it's referred to directly[2]
without any table lookup happening at all. Lua globals aren't really
variables at all; they're simply syntactic sugar for doing table
accesses on _G. This:

It seems that asking script coders to be aware of such issues and optimize their code for them is less than optimal.

I think that globals should be handled differently. Perhaps there should be an internal 'C' array of globals, maybe just pointers to the internals of the _G table. Then compiled references to said globals would just contain indexes into the array. If _G members are removed, then the corresponding global indexes would have to be marked nil somehow. I don't know the lua internals so I have no idea what complications this would introduce. I suspect it would have to be a 'Next Generation' feature.


--
Bryan White