[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Comparing userdata to 0 in Lua 5.0
- From: Yanninator <yanninator@...>
- Date: Thu, 06 Nov 2003 01:19:14 -0800
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?
Example:
function foo()
local pointer1 = GetSomePointerFromC();
local pointer2 = GetSomeOtherPointerFromC();
if (pointer1 == 0) then
-- pointer is NULL.
elseif (pointer1 == pointer2) then
-- addresses are the same.
end
end
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?
Thanks!