lua-users home
lua-l archive

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



> From: Leigh McRae 
> Sent: Tuesday, October 07, 2003 11:28 AM
> To: Lua list
> Subject: Re: Lua on the PlayStation2
> 
>   I didn't see a eq metamethod for Lua 4.  I will check again, if so I
> will
> use this.  I did write a function called AreEqual() for the scripters
but
> I
> felt dirty and it was really prone to error.
> 
>   Casting the value of a handle to a void pointer would work, as a
> previous
> post suggested.  Looking back on the problem, I am thinking that it
was
> more
> of a tolua issue I was having.  I ended up changing tolua to treat
Handles
> as numbers when maybe what I really wanted was void pointers.  I will
have
> to look at it again, thanks for the ideas.


That sounds like a better idea as I think toLua coerces number types
back to their basic type so I don't think you can type check using
typedef'd number types that are floating point. 

In Lua 4 changing the type to void* will create a new tagged type which
you could type check in your AreEqual() function. You might also create
HandleId() and HandleInstance() which extract the appropriate
information from the "pointer".

In Lua 5.0 you will to have to create a heavy data type for each handle
to use the equals metamethod. You can use light user data (basically a
pointer wrapper) to do the same as the above Lua 4 method. The light
user data was created because some users were storing object pointers in
doubles and there is obviously no type safety.

Nick

TD R*V