lua-users home
lua-l archive

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


Right, I know that this works, but what if I have say 80 parameters.
My solution in the end was to pass tables into the function.  I think
a cleaner solution might be to use some kind of class structure as
opposed to global functions like I'm doing now.  Anyway, I got the
scoping thing in my head now so I know what doesn't work.

thanks,
wes

On 5/31/07, Michael Surette <mjsurette@gmail.com> wrote:


On 5/31/07, Wesley Smith <wesley.hoke@gmail.com> wrote:
> Yes, I could, but image there are 30 or 40 of these functions.  The
> constructor would get rather long.  The real goal here is to pass in
> functions that describe behaviors to the constructor.  Sometimes,
> these behavior functions need data from the constructor itself.  I
> guess I could reorganize my constructor to take a table instead of a
> list of values and pass the table into the function instead.  That
> way, I can write a small constructor and general functions outside of
> it.
>
> wes
>
> On 5/31/07, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> > > What I'd like is f1's val upvalue to refer to constructor's local
> > > variable val.  Is this possible somehow through environments?
> >
> > Can't you define 'gen1' inside the constructor?
> >
> > -- Roberto
> >
>

Here's a simple example of what I believe Roberto is suggesting.  It works
well for me.  Am I missing something?

function gen(val)
  return function()
    print(val)
  end
end

f1=gen(1)
f2=gen(2)

f1()
f2()

--
Mike