Any awesome wm module starts from redefinition standard variables to local. Something like that
local table = table
local string = string
local tostring = tostring
What does it do? All code still working fine after deleting this lines.
Any awesome wm module starts from redefinition standard variables to local. Something like that
local table = table
local string = string
local tostring = tostring
What does it do? All code still working fine after deleting this lines.
It's purely an optimization thing. Local variables are faster to read/write than global variables. This is in part because globals are hash table lookups (e.g. foo
=> _G["foo"]
) and locals are VM register lookups. So it's not uncommon for modules that are going to be using a global a lot to alias it via a local variable.
For your code, unless you know something is going to be called a ton and is going to be a bottleneck, I wouldn't bother with this technique. Lua isn't C. You're trading performance for brevity and clarity. Don't trade it back until you know you have to.
"What does it do" is already answered.
For "why is it done": Back before awesome supported lua 5.2 (without deprecated functions), all modules used lua's module() function to set themselves up. This meant that values from the global variable became inaccessible and this "local trick" actually was necessary.