From 56fb854ad85dafff2016892bd6d2c5d24423bff0 Mon Sep 17 00:00:00 2001
From: Albert Krewinkel <albert@zeitkraut.de>
Date: Tue, 22 Aug 2017 22:02:30 +0200
Subject: Text.Pandoc.Lua: respect metatable when getting filters
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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.
---
 test/lua/metatable-catch-all.lua | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 test/lua/metatable-catch-all.lua

(limited to 'test/lua')

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}
+  )
+}
-- 
cgit v1.2.3