diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2017-08-22 22:02:30 +0200 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2017-08-22 22:56:51 +0200 |
commit | 56fb854ad85dafff2016892bd6d2c5d24423bff0 (patch) | |
tree | 277c4b145c306bc931466b81b4648df51fea274e /test/lua | |
parent | 915f201c785b776a24d4aafd0fce0bd8151c1ee2 (diff) | |
download | pandoc-56fb854ad85dafff2016892bd6d2c5d24423bff0.tar.gz |
Text.Pandoc.Lua: respect metatable when getting filters
This change makes it possible to define a catch-all function using lua's
metatable lookup functionality.
function catch_all(el)
…
end
return {
setmetatable({}, {__index = function(_) return catch_all end})
}
A further effect of this change is that the map with filter functions
now only contains functions corresponding to AST element constructors.
Diffstat (limited to 'test/lua')
-rw-r--r-- | test/lua/metatable-catch-all.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/lua/metatable-catch-all.lua b/test/lua/metatable-catch-all.lua new file mode 100644 index 000000000..05df16bbf --- /dev/null +++ b/test/lua/metatable-catch-all.lua @@ -0,0 +1,20 @@ +local num_inlines = 0 + +function catch_all(el) + if el.tag and pandoc.Inline.constructor[el.tag] then + num_inlines = num_inlines + 1 + end +end + +function Pandoc(blocks, meta) + return pandoc.Pandoc { + pandoc.Para{pandoc.Str(num_inlines)} + } +end + +return { + setmetatable( + {Pandoc = Pandoc}, + {__index = function(_) return catch_all end} + ) +} |