lua-users home
lua-l archive

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


Oops, sorry, if you're using 4.0 the closure method needs to be modified
to use up-values:

    function Anin_Index(t, i)
      if i == "Play" then
          return function(x,y) Play(%t, x, y) end
      else
          return nil
      end
    end

Sorry 'bout that. I've mostly been using 4.1-work4.

  - Tom 

On Mon, 13 May 2002, Tom Wrensch wrote:

> Here are two possibilities:
> 
> First of all you can change the call code to this:
> 
>     Animation = LoadAnimation( "BlackDog.dat" )
>     Animation:Play(1, 3)
> 
> (Note the change of the '.' to a ':' in the play call).
> 
> Another would be to build a closure to contain the extra information:
> 
>     function Anin_Index( t, i)
>       if i == "Play" then
>           return function(x, y) Play(t, x, y) end
>       else
>           return nil
>       end
>     end
>                  
> There are probably other ways to handle it, these are the two
> that come to mind.
> 
>   - Tom Wrensch
> 
> On Mon, 13 May 2002, Denis Lamarche wrote:
> 
> > I am working in Lua 4.0.  This is what I have and what I want to do:
> > 
> > function Anin_Index( t, i )
> >   if i == "Play" then
> >     return Play
> >   else
> >     return nil
> >   end
> > end
> > 
> > function LoadAnimation( name )
> >   return { NAME = name, ID = 1 }
> > end
> > 
> > ...And I have a tag set to this table that overides the index method so that 
> > when I do...
> > 
> > Animation = LoadAnimation( "BlackDog.dat" )
> > Animation.Play( 1, 3 )
> > 
> > ..The Play will actually call the 'c' function Play(), but I also want the 
> > ID of that table sent to 'C' with it.  How can this be done???  Can I add it 
> > to the stack thats being sent to 'C' ???
> 
> 
>