[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to properly initialize a module?
- From: Rob Hoelz <rob@...>
- Date: Tue, 6 Dec 2011 12:41:23 -0600
That's kind of a neat idiom; you could easily then do something like
this:
local canvas = require 'canvas' '/dev/fb0'
or even this:
local canvas = require 'canvas' {
device = '/dev/fb0'
}
You could even set __call on canvas, so "require 'canvas'" will return
the right object.
Neat idea. =)
On Tue, 6 Dec 2011 12:26:42 -0600
Tim Caswell <tim@creationix.com> wrote:
> I think stock lua's require allows this and I know I do in Luvit, but
> often I'll make the module itself be a function instead of a table.
> Then it would be
>
> local Canvas = require('canvas')
> local canvas = Canvas('/dev/fb0')
>
> On Tue, Dec 6, 2011 at 12:11 PM, Luiz Henrique de Figueiredo
> <lhf@tecgraf.puc-rio.br> wrote:
> >> So I implemented something like this:
> >>
> >> require 'canvas'
> >> canvas.init('/dev/fb0')
> >> -- canvas usage
> >
> > To make it prettier, export a function
> >
> > function canvas.with(options)
> > canvas.init(options)
> > return canvas
> > end
> >
> > and use it as
> >
> > local canvas = require'canvas'.with'/dev/fb0'
> > -- canvas usage
> >
>
Attachment:
signature.asc
Description: PGP signature