[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Class methods in lua
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 19 Dec 2000 00:12:23 -0200 (EDT)
>I'm having a problem with member functions however. What happens is when
>lua reads the line:
>
>returnvalue = myClassInstance.memfunc(param1, param2...)
>
>it calls the gettable tag method for myClassInstance with the index memfunc.
>How I deal with this is as follows:
>1. the gettable tag method for myClassInstance is called
>2. this tag method gets the table that contains all the get functions for
>myClass.
>3. the function corresponding to memfunc is retrieved from the myClass
>table, then pushed on the stack.
>4. lua calls the function in this manner: function(param1, param2 ...)
The problem is that the gettable tag method is called for the expression
"myClassInstance.memfunc", not for the whole thing. In other words, it
does not know you're calling a function yet.
One way to do this for the gettable tag method to return the function
corresponding to memfunc as userdata and then to setup a "function" tag method
for the tag of this userdata. In this "function" tag method, you'll have
the arguments as required and you just cast the userdata back to whatever it
was in C or C++.
--lhf