[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Isolated require for lua-require
- From: Rob Hoelz <rob@...>
- Date: Wed, 19 Sep 2012 17:26:25 +0200
Greeting Lua users,
I'm about to put the finishing touches on the first release of
lua-require (which will be renamed before its first release!). The last
thing
I need to do before the first release is implement an "isolated"
require. For those of you who don't know, the purpose of an isolated
require
is to load modules that would normally contaminate the global
environment in a way so that the variables they define would instead be
located
in the return value of require. Example:
-- test.lua
function foo()
print 'pollution'
end
-- main.lua
local test = require.isolated 'test'
assert(type(foo) == 'nil')
assert(type(test.foo) == 'function')
The question is, how strict should I make the isolated loader? Should I
just prevent a naive global assignment, like what's seen above? Should
I prevent
_G.foo = function() ... end? getfenv(0).foo = function() ... end?
getfenv(2).foo = function() ... end?
The reason I want the isolated loader in the first release is so I can
use Test.More in tests for other libraries, and it assigns directly to
_G. So I want to be able to
use it for my needs, but I also want to do it right.
Thanks,
Rob