lua-users home
lua-l archive

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


local variables can be accessed more efficiently at runtime than named identifier lookups. Locals are found at runtime as an array access (by index), whereas table lookups are a hash table lookup. So this is probably just an attempt to make frequently used function calls execute a little faster.

-- Tim Gogolin

On Sep 12, 2005, at 2:23 PM, William Trenker wrote:

From studying various Lua modules I see that experienced Lua

programmers usually set up a number of local variables that carry the
value of standard library functions, like this:

local assert, error, _G, loadstring, loadfile, _pcall, type, unpack,
xpcall = assert, error, _G, loadstring, loadfile, pcall, type, unpack,
xpcall

What is the point of this?  On the surface it appears to be redundant.
 But since it is often used by the experts I'm obviously missing
something important.

Thanks very much,
Bill