From c32cdda2bb58b63ab26ac9031295422e89fb81ca Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 5 Apr 2019 16:59:40 -0300 Subject: [PATCH] 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 ` 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 `` 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 ``. Adding a test for this would require compiling and loading a C extension. --- inspect.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inspect.lua b/inspect.lua index da01bdf..73f0a23 100644 --- a/inspect.lua +++ b/inspect.lua @@ -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('') self:puts(' -- ', escape(toStringResult)) + else + local str = tostring(v) + if str == "userdata: NULL" then + self:puts('') + else + self:puts('') + end end else self:puts('<', tv, ' ', self:getId(v), '>')