[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 13:48:03 -0600
I should probably clarify that example a bit; if you try this:
local m = require 'mymodule'
m.greet()
you'll see "Hello!". If you try this:
local m = require 'mymodule' 'Guten Tag!'
m.greet()
you'll see "Guten Tag!".
On Tue, 6 Dec 2011 13:45:56 -0600
Rob Hoelz <rob@hoelz.ro> wrote:
> Responses are inline.
>
> On Tue, 6 Dec 2011 11:17:12 -0800 (PST)
> Ezequiel García <elezegarcia@yahoo.com.ar> wrote:
>
> > --- El mar 6-dic-11, Rob Hoelz <rob@hoelz.ro> escribió:
> >
> > > De: Rob Hoelz <rob@hoelz.ro>
> > > Asunto: Re: How to properly initialize a module?
> > > Para: lua-l@lists.lua.org
> > > Fecha: martes, 6 de diciembre de 2011, 16:41
> > > 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'
> > > }
> >
> > I am confused about this. Is this valid syntax?
>
> Yup! The first example is equivalent to the following:
>
> local canvas = require('canvas')('/dev/fb0')
>
> And the second:
>
> local canvas = require('canvas')({ device = '/dev/fb0' })
>
> >
> > How would I implement from C side? What's the difference between
> > require 'foo'.func() and require 'foo' 'bar' ?
>
> "require 'foo'.func()" translates to something like this:
>
> local m = require('foo')
> m.func()
>
> whereas "require 'foo' 'bar'" translates to this:
>
> local m = require('foo')
> m('bar')
>
> You could implement my idiom from the C-side like this:
>
> https://gist.github.com/1439633
>
> -Rob
>
Attachment:
signature.asc
Description: PGP signature