Re: Adding params to functions
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Adding params to functions
- From: Tom Wrensch <twrensch@...>
- Date: 2002年5月13日 10:09:31 -0700 (PDT)
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 2002年5月13日, 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' ???