lua-users home
lua-l archive

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


On Mon, Nov 9, 2009 at 7:40 PM, liam mail <liam.list@googlemail.com> wrote:
>
>
> 2009/11/9 Duncan Cross <duncan.cross@gmail.com>
>>
>> On Mon, Nov 9, 2009 at 7:22 PM, liam mail <liam.list@googlemail.com>
>> wrote:
>> > I have come across something that I am unsure if it is expected
>> > behaviour or
>> > a bug and would like some help to identify which it is.
>> (...)
>> > int equal(lua_State* s)
>> > {
>> >     Int_wrapper* i1 = static_cast<Int_wrapper *>( lua_touserdata(s, 1)
>> > );
>> >     Int_wrapper* i2 = static_cast<Int_wrapper *>( lua_touserdata(s, 2)
>> > );
>> >     lua_pushinteger(s, i1->i == i2->i ? 1 : 0 );
>> >     return 1;
>> > }
>>
>> I believe that the __eq metamethod (as well as the other comparison
>> metamethods) must return a boolean in order to work properly, so that
>> may be your problem.
>>
>> -Duncan
>
> Duncan even if that is the case it would not effect the fact that the method
> is never called. I should also say it is not just the equality operator that
> displays this behaviour.
>

Okay, you're right, I've had a closer look at the code now and I think
the problem is that every time you use lua_pushcfunction(), this
creates a new, unique closure on the stack. This means that two
instances of the same C function pushed onto the stack will not be
equal to each other. Try instead using lua_pushcfunction() only once,
then lua_pushvalue() to get a copy of it.

-Duncan