[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: functions and upvalues
- From: "Mauro Iazzi" <mauro.iazzi@...>
- Date: Thu, 31 May 2007 23:58:49 +0200
On 31/05/07, Wesley Smith <firstname.lastname@example.org> wrote:
You're right. I will just have to make a table and pass it in.
Why simply not making val an argument to gen1? Arguments behave just as a local variables, if I understand correctly (i.e. they become upvalues).
Thus the code would simply be:
local val = 100
local f1 = generator(val)
Hope it helps.
PS: (please don't read)
if you want to have fun,
function bind_before(f, v) return function(...) return f(v, unpack(arg)) end end
function bind_after(f, v) return function(...) return f(unpack(arg), v) end end
gen1 = bind_before(bind_before, print)
constructor = bind_after(bind_before, 100)
sorry for being nerdy, I could not resist.