Skip to content

Evaluate box.NULL to false #4227

Answered by igormunkin
knazarov asked this question in Q&A
Discussion options

You must be logged in to vote

@knazarov, OK, let's start with Lua and LuaJIT manuals:

The condition expression of a control structure can return any value. Both false and nil are considered false. All values different from nil and false are considered true (in particular, the number 0 and the empty string are also true).

Pointer comparison: two compatible cdata pointers/arrays can be compared. The result is the same as an unsigned comparison of their addresses. nil is treated like a NULL pointer, which is compatible with any other pointer type.

Considering all sources above this behaviour is documented in both Lua language spec and FFI semantics description.

Moreover, …

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by igormunkin
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
wontfix This will not be worked on breaking change luajit misuse Issues related to LuaJIT API misuse (both Lua and Lua C)
5 participants
Converted from issue

This discussion was converted from issue #4227 on December 16, 2020 16:58.