lua-users home
lua-l archive

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

On Thu, Aug 21, 2008 at 1:25 PM, Alexander Gladysh <> wrote:
> One of my most ugly objects now have more than 60 methods (yes, I
> know, I should refactor this abomination out immediately, but I just
> do not have time for it yet).

put all methods in a separate file, prepend them with a module().
when you require() that file, you'll get a table with all non-local

what module() does is mainly creating a new table, and setting it as
the environment.  after that, all non-local functions will populate
that table instead of the original _G.

i've done this when i want a table with functions and don't want to
write something like:

t = {
 f1=function(...) ... end,
 f2=function(..)  ... end,

with module() it's just


function f1 (...)

function f2 (...)

i really want to like the first option, since i know it's the most
'functional', but the second one is a lot nicer to the eye, and using
module(), any non-local value gets stuffed into my table, so it works