Skip to content

Commit ddb9315

Browse files
committed
Handle light userdata (report it as '<pointer>')
PANDOC_WRITER_OPTIONS appears to use light userdata for some colors. This might be unintentional but it does no harm to work around it. Note: I don't know how to check for light userdata (its type() returns 'userdata') so I used pcall() to catch attempts to use it.
1 parent 6ba64ff commit ddb9315

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

logging.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ local function dump_(prefix, value, maxlen, level, add)
8989
local typ = (({boolean=1, number=1, string=1, table=1, userdata=1})
9090
[typename] and '' or typename)
9191

92+
-- light userdata is just a pointer (can't iterate over it)
93+
-- XXX is there a better way of checking for light userdata?
94+
if type(value) == 'userdata' and not pcall(pairs(value)) then
95+
value = '<pointer>'
96+
9297
-- modify the value heuristically
93-
if ({table=1, userdata=1})[type(value)] then
98+
elseif ({table=1, userdata=1})[type(value)] then
9499
local valueCopy, numKeys, lastKey = {}, 0, nil
95100
for key, val in pairs(value) do
96101
-- pandoc >= 2.15 includes 'tag', nil values and functions
@@ -125,6 +130,10 @@ local function dump_(prefix, value, maxlen, level, add)
125130
local quo = typename == 'string' and '"' or ''
126131
add(string.format('%s%s%s%s%s%s%s%s', indent, prefix, presep, typ,
127132
typsep, quo, value, quo))
133+
-- light userdata is just a pointer (can't iterate over it)
134+
-- XXX is there a better way of checking for light userdataXS?
135+
elseif valtyp == 'userdata' and not pcall(pairs(value)) then
136+
add(string.format('%s%s%s%s <pointer>', indent, prefix, presep, typ))
128137
elseif ({table=1, userdata=1})[valtyp] then
129138
add(string.format('%s%s%s%s%s{', indent, prefix, presep, typ, typsep))
130139
-- Attr and Attr.attributes have both numeric and string keys, so

0 commit comments

Comments
 (0)