[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: require() passing arguments to module?
- From: David Manura <dm.lua@...>
- Date: Sat, 5 Nov 2011 23:28:27 -0400
On Sat, Nov 5, 2011 at 11:08 PM, HyperHacker <hyperhacker@gmail.com> wrote:
> I suppose you could take Roberto's example further and turn modules
> into "factories" of sorts:
> local foo = require('foo').create(some, args, here)
> so require('foo') just returns a function that will create an instance
> of the foo module. There might be a better name for this pattern?
That's no different from implementing a class in a module. If you like,
function new(name, ...) return require(name).create(...) end
local afoo = new('foo', some, args, here)