Re: Modules that are functions
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Modules that are functions
- From: Petite Abeille <petite.abeille@...>
- Date: 2013年11月21日 23:58:35 +0100
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 )