mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
add a special case for NULL userdata
When interpreting userdata values using 'inspect', the numeric identifiers are useful to match identify of pointers (comparing the low counters like `<userdata 3> is easier than reading long pointers like `userdata: 0x749abc39efa29`). However, the `NULL` pointer is enough of a special case that it is important to know when one of those numbered pointers happens to be `NULL`. When one is dealing with things like JSON parsers, where the only usual userdata is `cjson.null`, one gets accostumed over time to interpret `<userdata 1>` to mean `NULL`. This is not obvious, however, and a seasoned user will trip up the day another userdata is used in the same table and `NULL` is now `<userdata 2>`. Adding a test for this would require compiling and loading a C extension.
This commit is contained in:
parent
6e7f2dce9b
commit
c32cdda2bb
@ -309,9 +309,16 @@ function Inspector:putValue(v)
|
||||
elseif tv == 'userdata' then
|
||||
local mt = getmetatable(v)
|
||||
local toStringResult = mt and getToStringResultSafely(v, mt)
|
||||
self:puts('<', tv, ' ', self:getId(v), '>')
|
||||
if toStringResult then
|
||||
self:puts('<userdata ', self:getId(v), '>')
|
||||
self:puts(' -- ', escape(toStringResult))
|
||||
else
|
||||
local str = tostring(v)
|
||||
if str == "userdata: NULL" then
|
||||
self:puts('<userdata NULL>')
|
||||
else
|
||||
self:puts('<userdata ', self:getId(v), '>')
|
||||
end
|
||||
end
|
||||
else
|
||||
self:puts('<', tv, ' ', self:getId(v), '>')
|
||||
|
Loading…
Reference in New Issue
Block a user