[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: modules, require, magic
- From: Geoff Leyland <geoff_leyland@...>
- Date: Wed, 19 Oct 2011 19:04:17 +1300
On 19/10/2011, at 6:25 PM, Hisham wrote:
> In terms of "fixing module()", I think Fabio's implementation is right
> on the money:
>
> http://article.gmane.org/gmane.comp.lang.lua.general/84283
>
> It shows that a sane implementation of module() can be done with
> standard Lua mechanisms. Do any of the anti-module proponents see any
> problems with that design?
Would taking a shallow copy of the module to hide _G would make
-- mod.lua
module("mod")
count = 1
function increment() count = count + 1; print(count) end
-- main.lua
local mod = require("mod")
print(mod.count)
mod.increment()
print(mod.count)
print "1 2 1" rather than "1 2 2"?
Cheers,
Geoff
- References:
- modules, require, magic, Eduardo Ochs
- Re: modules, require, magic, Javier Guerra Giraldez
- Re: modules, require, magic, Petite Abeille
- Re: modules, require, magic, Sam Roberts
- Re: modules, require, magic, David Manura
- Re: modules, require, magic, Hisham