lua-users home
lua-l archive

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


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