luaL_checkudata (5.1-rc4) bug ?

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

luaL_checkudata (5.1-rc4) bug ?

Jérôme VOLPOËT
Hello everyone,

I'm using 5.02 for a while and tried to install 5.1rc4.

It seems that there is a bug in the new implementation of luaL_checkudata :
Everything works fine if the index ( ud ) is positive, but there seems to be 
a problem when it's negative :

for example, I use it with index -1, the result is that it throw an error : 
the lua_getmetatable used in the test try to extract metatable from the 
result of lua_getfield( at index -1 ) but not of my own usertype (which is 
now a index -2)

Am I right, or am I doing somthing wrong elsewhere ?


Reply | Threaded
Open this post in threaded view
|

Re: luaL_checkudata (5.1-rc4) bug ?

Roberto Ierusalimschy
> It seems that there is a bug in the new implementation of luaL_checkudata :
> Everything works fine if the index ( ud ) is positive, but there seems to be 
> a problem when it's negative :

All luaL_check* functions should be called only with positive indices
(more specifically, with indices to parameters).

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: luaL_checkudata (5.1-rc4) bug ?

Jérôme VOLPOËT
Thanks for the answer.
So why not prototyping these functions with unsigned int ?

----- Original Message ----- 
From: "Roberto Ierusalimschy" <[hidden email]>
To: "Lua list" <[hidden email]>
Sent: Friday, February 17, 2006 4:20 PM
Subject: Re: luaL_checkudata (5.1-rc4) bug ?


|> It seems that there is a bug in the new implementation of luaL_checkudata 
:
| > Everything works fine if the index ( ud ) is positive, but there seems 
to be
| > a problem when it's negative :
|
| All luaL_check* functions should be called only with positive indices
| (more specifically, with indices to parameters).
|
| -- Roberto
| 


Reply | Threaded
Open this post in threaded view
|

Re: luaL_checkudata (5.1-rc4) bug ?

Luiz Henrique de Figueiredo
> So why not prototyping these functions with unsigned int ?

That won't give you any errors if you call it with negative numbers.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: luaL_checkudata (5.1-rc4) bug ?

Jérôme VOLPOËT
That's true, but I will have a compiler warning and it seems more clear that 
I'm not allowed to do that when I read the prototype.
BTW, it's not very important.

I don't want to make a troll, and it will be my mast post on this subject, 
but it worked fine with previous version, I'm not seeing why it's impossible 
to allow negative index in the new one. And, last remark, it seems a good 
idea to write it in the new manual (perhaps i've missed it because i did not 
re-read it from begin to end :p )


----- Original Message ----- 
From: "Luiz Henrique de Figueiredo" <[hidden email]>
To: "Lua list" <[hidden email]>
Sent: Friday, February 17, 2006 4:30 PM
Subject: Re: luaL_checkudata (5.1-rc4) bug ?


|> So why not prototyping these functions with unsigned int ?
|
| That won't give you any errors if you call it with negative numbers.
| --lhf
| 


Reply | Threaded
Open this post in threaded view
|

Re: luaL_checkudata (5.1-rc4) bug ?

Roberto Ierusalimschy
> And, last remark, it seems a good idea to write it in the new manual


  Several functions in the auxiliary library are used to check C function
  arguments. Their names are always luaL_check* or luaL_opt*. All of these
  functions raise an error if the check is not satisfied. Because the
  error message is formatted for arguments (e.g., "bad argument #1"), you
  should not use these functions for other stack values.

-- Roberto