lua-users home
lua-l archive

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

> -----Original Message-----
> From: []
> Sent: Tuesday, October 14, 2003 12:50 PM
> To: Lua list
> Subject: RE: constants?
> > I know they're not strictly necessary, but you should get smaller,
> > faster Lua VM code if you use a pre-processor. The variable names
> > not stored, and they don't have to be looked up in a table (global
> > user) to find the value.
> You can achieve exactly the same result by using local variables.

Can't you query the names of locals through the debug interface?

"debug.getlocal (level, local)
This function returns the name and the value of the local variable with
index local of the function at level level of the stack. (The first
parameter or local variable has index 1, and so on, until the last
active local variable.) The function returns nil if there is no local
variable with the given index, and raises an error when called with a
level out of range. (You can call getinfo to check whether the level is

If you're stretched for memory, <cough> console development </cough>,
you might want to avoid extra unwanted baggage and do it CPP style. So,
I don't think they're exactly the same, but you could get a speed
increase by using locals.