[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Audience for globals discussion?
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 19 Aug 2010 11:23:08 +0200
On Wed, Aug 18, 2010 at 1:28 PM, Rob Kendrick <rjek@rjek.com> wrote:
> It's difficult to put a number on it. Personally, I avoid globals
> unless it's absolutely necessary.
And now we have the no-globals pattern:
local G = _G
local M = {}
local _ENV=nil
function M.export() G.print("paranoid module"); end
return M
Any access to the global table will result in a 'accessing nil upvalue
_ENV' error, which is arguably preferable to a silent nil result or
nil assign.
You can of course do 'local math,io = math,io' etc upfront to make
typing a wee bit easier.
steve d.