Lua (3.1) object comparison in C

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua (3.1) object comparison in C

Cyril Zorin
Hi,

What's an idiomatic way to compare two lua_Objects in C? I'm guessing  
the naÏve way is to make sure their types are equal, convert values  
to C based on types, and check the values.

However, is there some kind of easier way to do this?

Thanks,
Cyril.
Reply | Threaded
Open this post in threaded view
|

Re: Lua (3.1) object comparison in C

Javier Guerra Giraldez
On Saturday 20 May 2006 11:25 am, Cyril Zorin wrote:
> Hi,
>
> What's an idiomatic way to compare two lua_Objects in C? I'm guessing

from the manual (3.4 - Querying the Stack):

The API also contains functions to compare two values in the stack:

       int lua_equal    (lua_State *L, int index1, int index2);
       int lua_rawequal (lua_State *L, int index1, int index2);
       int lua_lessthan (lua_State *L, int index1, int index2);

lua_equal and lua_lessthan are equivalent to their counterparts in Lua (see
2.5.2). lua_rawequal compares the values for primitive equality, without
metamethods. These functions return 0 (false) if any of the indices are
non-valid.

--
Javier

attachment0 (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Lua (3.1) object comparison in C

Cyril Zorin
Javier,

I'm working with Lua 3.1 (as mentioned in the original email's  
title), and the Lua 3.1 manual does not contain the below functions.

Cyril.

On 20-May-06, at 12:42 PM, Javier Guerra wrote:

> On Saturday 20 May 2006 11:25 am, Cyril Zorin wrote:
>> Hi,
>>
>> What's an idiomatic way to compare two lua_Objects in C? I'm guessing
>
> from the manual (3.4 - Querying the Stack):
>
> The API also contains functions to compare two values in the stack:
>
>        int lua_equal    (lua_State *L, int index1, int index2);
>        int lua_rawequal (lua_State *L, int index1, int index2);
>        int lua_lessthan (lua_State *L, int index1, int index2);
>
> lua_equal and lua_lessthan are equivalent to their counterparts in  
> Lua (see
> 2.5.2). lua_rawequal compares the values for primitive equality,  
> without
> metamethods. These functions return 0 (false) if any of the indices  
> are
> non-valid.
>
> --
> Javier