lua-users home
lua-l archive

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


On Thursday 11 December 2003 07:47, Enrico Colombini wrote:
> I'd like my users to be able to type in hexadecimal (and possibly binary)
> constants in as painless a way as possible.

If you're not too concerned about 'polish', you could add a __index hook to 
the global table which picks up identifiers of the format HxFFFF or similar 
and returns the appropriate value. You'd probably want a __newindex method 
which complains if someone tries to assign to such a value (which might be a 
performance hit depending on your use of globals, but maybe could be turned 
off in final builds). It would still be possible to redefine the constants 
locally though, but it seems unlikely that anyone would... if nothing else, 
most people use all lowercase for locals.

 -- Jamie Webb

Eat right, exercise, die anyway.