Evaluate box.NULL to false #4227
-
Currently the following code prints local a = box.NULL
if a then
print('surprise')
end It is not obvious for many new and existing users of tarantool, and is a constant source of bugs, because |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
We cannot simply replace msgpack.NULL (and its alias box.NULL) with nil because Lua doesn’t distinguish nil from absence of value in a table. But even though msgpack.NULL equals to nil it still has type cdata and thus the statement "if msgpack.NULL" would be always evaluated to true as well as "msgpack.NULL == nil" and there seem to be no way around it. Unless of course we consider implementing macros (or use someone else's implementation of macros for lua, e.g. - https://github.com/stevedonovan/LuaMacro). This would allow to keep the existing functionality and being able to use box.NULL in most intuitive straightforward way at the same time. |
Beta Was this translation helpful? Give feedback.
-
Related: tarantool/doc#561 |
Beta Was this translation helpful? Give feedback.
-
@knazarov, OK, let's start with Lua and LuaJIT manuals:
Considering all sources above this behaviour is documented in both Lua language spec and FFI semantics description. Moreover, let's take into account the Java spec:
Thereby Java Compiler obligues the one to use an explicit comparisons within a conditional expression and I see no problem with it. We can start flaming about value evaluation/conversion to boolean in other languages but it is more a hack than a best practice. Assume we make this change. What is the reason to stop with We can continue the discussion, but for now I see lots of work with no sense for such breakage and propose to close this issue with no changes to be provided. |
Beta Was this translation helpful? Give feedback.
-
Related issue - #1666 |
Beta Was this translation helpful? Give feedback.
@knazarov, OK, let's start with Lua and LuaJIT manuals:
Considering all sources above this behaviour is documented in both Lua language spec and FFI semantics description.
Moreover, …