[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: modules, require, magic
- From: steve donovan <steve.j.donovan@...>
- Date: Wed, 19 Oct 2011 10:28:40 +0200
On Wed, Oct 19, 2011 at 9:41 AM, Geoff Leyland
<geoff_leyland@fastmail.fm> wrote:
> That looks like it's on the right track.
I note that the definition of module() does not actually do anything
except set _NAME, so that you can create modules this way without
actually calling it.
-- fred.lua
--module 'fred' -- ha, don't really need to call this!
function answer()
return 42
end
function go ()
show 'hello'
end
function show (s)
print(s)
end
It gets away with the ugly package.seeall, but has much the same
behaviour - and sandboxers still need to be aware that globals can be
accessed through the module table.
local fred = require 'fred'
print(fred.answer())
fred.go()
print(fred.io) -- !!
Although the no-magic style still works, it automatically becomes
burdened by all the indirection, unless you're careful to give local
aliases up front.
steve d.
- 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
- Re: modules, require, magic, Geoff Leyland
- Re: modules, require, magic, Hisham
- Re: modules, require, magic, Geoff Leyland