lua-users home
lua-l archive

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


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.