lua-users home
lua-l archive

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

On 31/05/07, Wesley Smith <> 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:

function gen1(val)
   return function()

function constructor(generator)
   local val = 100

   return function()

      local f1 = generator(val)



-> 100

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.