lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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