[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Function at line ### has more than 60 upvalues
- From: "Eric Tetz" <erictetz@...>
- Date: Thu, 21 Aug 2008 12:21:18 -0700
Alexander Gladysh <agladysh@gmail.com> wrote:
> Is there something more graceful than straight:
>
> local f1 = function(t)
> t.method1 = method1e
> t.method2 = method2
Just put your methods into a table, then your factory has only one upvalue and you can copy the methods into a new table with a loop.
function clone(t, rv) -- shallow table copy
rv = rv or {}
for k,v in pairs(t) do rv[k] = v end
end
local factory
do
local prototype = {}
function prototype:method1() end
function prototype:method2() end
function prototype:methodN() end
factory = function() return clone(prototype) end
end