[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Modules that are functions
- From: Craig Barnes <craigbarnes85@...>
- Date: Thu, 21 Nov 2013 22:21:48 +0000
On 21 November 2013 21:59, Marc Lepage <mlepage@antimeta.com> wrote:
> PiL talks about a style of data description that looks like:
>
> entry {
> title='xxx',
> url='yyy'
> }
>
> http://www.lua.org/pil/10.1.html
>
> If I wanted to use this, and wanted entry to be a module, could I just make
> a module that returns a function instead of a table?
>
> local entry = require 'entry'
> should still work.
>
> I don't care about anything like being able to call entry.someFunc.
>
> Is a module that is a function (not a table) a reasonable thing? Is it a
> common idiom (in this case)? Are there alternatives?
>
> Appreciate feedback.
>
It seems quite reasonable to me. I've seen quite a few object-oriented
modules that return only a "new" function, with everything else it
implements being methods on the instance it creates.