lua-users home
lua-l archive

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


On Sat, Oct 5, 2019 at 11:36 PM Phil Leblanc wrote:
So would you encourage developers to start using "return false, msg"
in case of error instead of return nil, msg ?

No!
The manual says that in Lua 5.4 "fail" equals to nil.
So, other people's code might rely on it when using your module.


"fail" might switch its value in some future Lua version.
To survive this event, you will have to do the following:

1) everywhere in your existing Lua code, when checking the status, you must replace
if status == nil then
with
if not status then

2) everywhere in your existing C code, when checking the status, you must replace
lua_isnil
with
!lua_toboolean

3) everywhere in your existing Lua code, where standard library functions were reimplemented, when returning the status, you must replace
return nil, msg
with
return false, msg

4) everywhere in your existing C code, where standard library functions were reimplemented, when preparing status to be returned, you must replace
lua_pushnil
to
lua_pushboolean


You can apply changes #1 and #2 right now without deferring to the actual switching of "fail".
You can not apply changes #3 and #4 right now.