[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Modules that are functions
- From: Coda Highland <chighland@...>
- Date: Thu, 21 Nov 2013 15:27:07 -0800
On Thu, Nov 21, 2013 at 2:58 PM, Petite Abeille
<petite.abeille@gmail.com> wrote:
>
> On Nov 21, 2013, at 11:32 PM, Kevin Martin <kev82@khn.org.uk> wrote:
>
>> 2) I can guarantee that at some point in the future, that module which currently only has one function will need another, and the rewrite will be horrific if not returning a table.
>
> Meh… behold the functable:
>
> local aFunction = function() return 'Yeah!' end
> debug.setmetatable( aFunction, { __index = function( self, aKey ) return aKey end } )
>
> print( aFunction() )
> print( aFunction.foo )
> print( aFunction.bar )
> print( aFunction.baz )
>
Or of course go the other way around and return a table that's also
callable, which is probably preferable for reflection.
/s/ Adam