From 5416fb14aba9804ce4a227a4ebd8228d82aa658e Mon Sep 17 00:00:00 2001
From: Albert Krewinkel <albert@zeitkraut.de>
Date: Sun, 16 Apr 2017 21:00:01 +0200
Subject: [PATCH] Lua filter: allow natural access to meta elements

Meta elements that are treated as lua tables (i.e. MetaList,
MetaInlines, MetaBlocks, and MetaMap), are no longer wrapped in an
additional table but simply marked via a metatable.  This allows
treating those meta values just like normal tables, while still making
empty elements of those values distinguishable.
---
 data/pandoc.lua                       | 31 ++++++++++++++++-----------
 src/Text/Pandoc/Lua/StackInstances.hs |  2 +-
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/data/pandoc.lua b/data/pandoc.lua
index 6a4a2a8df..dfa67cdcc 100644
--- a/data/pandoc.lua
+++ b/data/pandoc.lua
@@ -166,35 +166,40 @@ end
 -- @function MetaList
 -- @tparam {MetaValue,...} meta_values list of meta values
 
---- Meta boolean
--- @function MetaBool
--- @tparam boolean bool boolean value
-
 --- Meta map
 -- @function MetaMap
 -- @tparam table a string-index map of meta values
-
---- Meta string
--- @function MetaString
--- @tparam string str string value
 M.meta_value_types = {
   "MetaBlocks",
-  "MetaBool",
   "MetaInlines",
   "MetaList",
   "MetaMap",
-  "MetaString"
 }
 for i = 1, #M.meta_value_types do
   M[M.meta_value_types[i]] = M.MetaValue:create_constructor(
     M.meta_value_types[i],
     function(content)
-      return {c = content}
-    end,
-    "content"
+      return content
+    end
   )
 end
 
+--- Creates string to be used in meta data.
+-- Does nothing, lua strings are meta strings.
+-- @function MetaString
+-- @tparam string str string value
+function M.MetaString(str)
+  return str
+end
+
+--- Creates boolean to be used in meta data.
+-- Does nothing, lua booleans are meta booleans.
+-- @function MetaBool
+-- @tparam boolean bool boolean value
+function M.MetaBool(bool)
+  return bool
+end
+
 ------------------------------------------------------------------------
 -- Blocks
 -- @section Block
diff --git a/src/Text/Pandoc/Lua/StackInstances.hs b/src/Text/Pandoc/Lua/StackInstances.hs
index 9ba28b58e..52151ce64 100644
--- a/src/Text/Pandoc/Lua/StackInstances.hs
+++ b/src/Text/Pandoc/Lua/StackInstances.hs
@@ -140,7 +140,7 @@ peekMetaValue :: LuaState -> Int -> IO (Maybe MetaValue)
 peekMetaValue lua idx = do
   -- Get the contents of an AST element.
   let elementContent :: StackValue a => IO (Maybe a)
-      elementContent = getTable lua idx "c"
+      elementContent = peek lua idx
   luatype <- ltype lua idx
   case luatype of
     TBOOLEAN -> fmap MetaBool <$> peek lua idx