Is it normal that luaL_checkudata() makes my program to dye

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it normal that luaL_checkudata() makes my program to dye

Laurent FAILLIE
Hello,

Reading example in https://www.lua.org/pil/28.2.html, I guessed that luaL_checkudata() only return a NULL pointer if the argument doesn't match an user data of the given type.
But unfortunately, it raise a fatal error :

My code is

...
        } else if( (r = luaL_checkudata(L, -1, "SelSharedFunc")) )
            func = *r;

        puts("bla bla"); ...

but puts() is never reached if the argument is not matching and raise following error :

Selenites/MQTT.sel:53: bad argument #-2 to 'Subscribe' (SelSharedFunc expected, got nil)

Did I misunderstood the documentation or there is another problem ?

Thanks

Laurent

Reply | Threaded
Open this post in threaded view
|

Re: Is it normal that luaL_checkudata() makes my program to dye

Peter Cawley
PiL on the web refers to Lua 5.0, where the behaviour was different.
Compare https://github.com/lua/lua/blob/v5_0/lauxlib.c#L132 to
https://github.com/lua/lua/blob/v5_1/lauxlib.c#L124

On Tue, May 1, 2018 at 10:36 PM, Laurent FAILLIE <[hidden email]> wrote:

> Hello,
>
> Reading example in https://www.lua.org/pil/28.2.html, I guessed that
> luaL_checkudata() only return a NULL pointer if the argument doesn't match
> an user data of the given type.
> But unfortunately, it raise a fatal error :
>
> My code is
>
> ...
>         } else if( (r = luaL_checkudata(L, -1, "SelSharedFunc")) )
>             func = *r;
>
>         puts("bla bla"); ...
>
> but puts() is never reached if the argument is not matching and raise
> following error :
>
> Selenites/MQTT.sel:53: bad argument #-2 to 'Subscribe' (SelSharedFunc
> expected, got nil)
>
> Did I misunderstood the documentation or there is another problem ?
>
> Thanks
>
> Laurent
>

Reply | Threaded
Open this post in threaded view
|

Re: Is it normal that luaL_checkudata() makes my program to dye

Javier Guerra Giraldez
In reply to this post by Laurent FAILLIE
On 1 May 2018 at 22:36, Laurent FAILLIE <[hidden email]> wrote:
> Hello,
>
> Reading example in https://www.lua.org/pil/28.2.html, I guessed that
> luaL_checkudata() only return a NULL pointer if the argument doesn't match
> an user data of the given type.
> But unfortunately, it raise a fatal error :

try luaL_testudata() [1]


[1]: https://www.lua.org/manual/5.3/manual.html#luaL_testudata

Reply | Threaded
Open this post in threaded view
|

Re: Is it normal that luaL_checkudata() makes my program to dye

Sean Conner
In reply to this post by Laurent FAILLIE
It was thus said that the Great Laurent FAILLIE once stated:
> Hello,
>
> Reading example in https://www.lua.org/pil/28.2.html, I guessed that
> luaL_checkudata() only return a NULL pointer if the argument doesn't match
> an user data of the given type.

  It raises an error if the item on the stack doesn't match.  If you check
the manual, on the right hand side of the function prototype for
luaL_checkudata(), you should see a '[-0,+0,v]' which indicated it can throw
an error.

  -spc


Reply | Threaded
Open this post in threaded view
|

Re: Is it normal that luaL_checkudata() makes my program to dye

Laurent FAILLIE
In reply to this post by Javier Guerra Giraldez
Thanks all for your reply.

unfortunately, luaL_testudata() appeared with 5.2 ... and I'm trying to be compatible with 5.1 as well.

So I created a custom wrapper for 5.1

Bye

Laurent
Le mardi 1 mai 2018 à 23:52:19 UTC+2, Javier Guerra Giraldez <[hidden email]> a écrit :


On 1 May 2018 at 22:36, Laurent FAILLIE <[hidden email]> wrote:
> Hello,
>
> Reading example in https://www.lua.org/pil/28.2.html, I guessed that
> luaL_checkudata() only return a NULL pointer if the argument doesn't match
> an user data of the given type.
> But unfortunately, it raise a fatal error :

try luaL_testudata() [1]



[1]:
https://www.lua.org/manual/5.3/manual.html#luaL_testudata