lua-users home
lua-l archive

Re: Idea for a new kind of require

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


On Friday, August 24, 2012 08:53:05 AM Rob Hoelz wrote:
> -- Loading modules with arguments
> 
> require('foo.with.config', { ... }) -- the arguments are passed
> directly to the chunk
> 
> I've seen this requested a few times, and I've also wished for it in my
> own modules.
> 
To allow a module to be loaded with different arguments, why not store the 
module in a table keyed on the serialized argument?
 require 'foo'
 -- does this internally
 package.loaded['foo'][''] = load('foo', ...)('foo')
 require('foo', {"a", 5})
 -- does this
 package.loaded['foo']['1="a";2=5'] = load('foo', ...)('foo',{"a",5})
Or something like that.
-- 
tom <telliamed@whoopdedo.org>

AltStyle によって変換されたページ (->オリジナル) /