return nil vs no return

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

return nil vs no return

Albert Chan
c function called from lua that supposed to return nil,
can I simplify code by return 0, instead of lua_pushnil(L); return 1 ?

Seems both accomplish the same thing.

function no_return () end

= no_return() == nil
true

x = 123
x = no_return()
= x
nil




Reply | Threaded
Open this post in threaded view
|

Re: return nil vs no return

Soni "They/Them" L.


On 2018-03-11 12:49 PM, Albert Chan wrote:

> c function called from lua that supposed to return nil,
> can I simplify code by return 0, instead of lua_pushnil(L); return 1 ?
>
> Seems both accomplish the same thing.
>
> function no_return () end
>
> = no_return() == nil
> true
>
> x = 123
> x = no_return()
> = x
> nil
>
>
>
>

select("#", no_return()) == 0

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: return nil vs no return

Albert Chan
I was checking if Luiz's module random.c return unbiased random integers.
The code return 0 for "bad" range, instead of lua_pushnil(L); return 1

If the only difference is select('#', ...) = 0 instead of 1, I guess return 0 is ok

BTW, random.c did NOT return unbiased random integers.