lua-users home
lua-l archive

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

Hi folks,

Here's a question you will likely find trivial. It appears to be generating
talk at work...

What happens when one compare's userdata with the value 0 (or any other
number for that matter) in Lua?


function foo()
    local    pointer1 = GetSomePointerFromC();
    local    pointer2 = GetSomeOtherPointerFromC();

    if (pointer1 == 0) then
        -- pointer is NULL.
    elseif (pointer1 == pointer2) then
        -- addresses are the same.

More precisely, is it safe (and correct) to compare a pointer
(lightuserdata) with the number 0 in order to determine if it's NULL? If
not, what would be the correct way to determine whether a pointer from C is
NULL or not? Would a IsPointerNULL() C function be recommended?