[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: local "module" pattern without module [was Re: [ANN] SLAXML - pure Lua, robust-ish, SAX-like streaming XML processor]
- From: Tomas Guisasola Gorham <tomas@...>
- Date: Mon, 18 Feb 2013 18:21:13 -0300 (BRT)
Hi Gavin
On Mon, 18 Feb 2013, Gavin Kistner wrote:
Here's what I ended up going with, as it only requires a change to the master
file. I'd be interested in comments on why this might be a bad idea.
### master.lua
local m = {}
local env = getfenv(0)
setfenv(0,setmetatable({MASTER=m},{__index=env}))
require 'simple'
require 'multi'
require 'shared1'
require 'shared2'
require 'reference'
setfenv(0,env)
return m
All other files are unchanged, except the usage itself which gets a `local
MASTER = require 'master'`
Written up at:
http://stackoverflow.com/q/14942472/405017
Maybe I've missed something, but why don't you just:
return {
simple = require"simple",
multi = require 'multi',
shared1 = require 'shared1',
shared2 = require 'shared2',
reference = require 'reference',
}
Of course you'll end up with a hierarchical structure, which
couldn't be what you want. But I am sure it is worth it!
Regards,
Tomás