lua-users home
lua-l archive

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


You may also return the standard module table, but add a metatable to it that has a __call field that holds a function.

This way you may return more than a function, but still can use the whole module like a function by calling it.

I did this some times,

Oliver
 
Am 06.03.2014 09:24, schrieb Journeyer J. Joh:
O.K.

So simple!

Thank you Steve Donovan!


----------------------------------------
Journeyer J. Joh
o o s a p r o g r a m m e r
a t
g m a i l  d o t  c o m
----------------------------------------


2014-03-06 17:20 GMT+09:00 steve donovan <steve.j.donovan@gmail.com>:
On Thu, Mar 6, 2014 at 10:14 AM, Journeyer J. Joh
<oosaprogrammer@gmail.com> wrote:
> I want my module return a function.
> For my particular case, Is there any convenient function like module(...)?

Just something like this:

-- ftest.lua
return function(a)
  return {value = a}
end

then require 'ftest' will give you a function, which you can call.