[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: local scope once again
- From: Tim Gogolin <tgogolin@...>
- Date: Tue, 12 Dec 2006 15:05:38 -0600
This behaviour means that all earlier local declarations of the
variable become completely shadowed by later local declarations at the
same scope. I am afraid it makes code less readable.
local x="first declaration"
local x="second declaration" -- the same scope
The first line is now completely irrelevant, because its version of
'x' is not accessible by regular Lua means (except for debug library).
Is there any particular reason to design Lua local scope rules this
"because its version of 'x' is not accessible by regular Lua means"
Not entirely true.
-- typed in Mail.app; not tested; etc.
local function getFirstX() return x end
local function setFirstX(n) x = n end
local function getSecondX() return x end
local function setSecondX(n) x = n end
-- can now access either 'x' via the appropriate functions
As for how common such a coding pattern might be, I leave to others
to debate :-)
-- Tim Gogolin