[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Module system curiosity
- From: Jim Jennings <jennings.durham.nc+lua@...>
- Date: Sun, 6 Jun 2010 14:03:59 -0400
On Sun, 30 May 2010 16:21:44 +0100, Matthew Wild <mwild1@gmail.com> wrote:
> - my concern isn't protecting the default environment as
> you state, but rather allow my re-environmented (I need to use this
> phrase more) functions to load modules, independent of each other.
>
> As it is, when they call require() most module tables end up out of
> their reach, unless I provide them with an __index on their
> environment to _G, and then suddenly they aren't so independent from
> the main program - which isn't what I wanted.
I needed the same property -- modules that were independent of each
other and of the main environment. I wrote a layer that rides on top
of the Lua module system that provides this property. It's called
Darwin, and you can find it at: http://lua-users.org/wiki/JimJennings
The Darwin module system is completely backwards compatible with
regular Lua modules. Existing Lua modules can be used as-is, or you
can Darwin-ize them by writing a one- or two-line declaration that
will tell Darwin to put it into its own environment when you load it.
I use this system everyday. I will port it to Lua 5.2 at some point,
when the environment-related decisions are settled.
--Jim
PS -- You can use Darwin to guarantee complete safety (i.e. no module
can possibly interfere with another module) if you remove getfenv()
and setfenv() from the default environment. When you need a module
that requires these functions, you can easily make them available --
in this way, "trusted" modules can use these functions (which are
security leaks) but "untrusted" modules cannot.