[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to properly initialize a module?
- From: Tim Caswell <tim@...>
- Date: Tue, 6 Dec 2011 12:26:42 -0600
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
>