aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/pandoc.lua15
-rw-r--r--doc/lua-filters.md11
-rw-r--r--src/Text/Pandoc/Lua/StackInstances.hs12
3 files changed, 31 insertions, 7 deletions
diff --git a/data/pandoc.lua b/data/pandoc.lua
index 74263b1fd..d8f7adb97 100644
--- a/data/pandoc.lua
+++ b/data/pandoc.lua
@@ -153,6 +153,21 @@ end
M.Doc = M.Pandoc
------------------------------------------------------------------------
+-- Meta
+-- @section Meta
+
+--- Create a new Meta object. It sets the metatable of the given table to
+--- `Meta`.
+-- @function Meta
+-- @tparam meta table table containing document meta information
+M.Meta = {}
+M.Meta.__call = function(t, meta)
+ return setmetatable(meta, self)
+end
+setmetatable(M.Meta, M.Meta)
+
+
+------------------------------------------------------------------------
-- MetaValue
-- @section MetaValue
M.MetaValue = Element:make_subtype{}
diff --git a/doc/lua-filters.md b/doc/lua-filters.md
index 8cdb96194..11643da84 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -617,6 +617,17 @@ Lua functions for pandoc scripts.
`meta`:
: document meta data
+## Meta
+
+[`Meta (table)`]{#Meta}
+
+: Create a new Meta object.
+
+ Parameters:
+
+ `table`:
+ : table containing document meta information
+
## MetaValue
[`MetaBlocks (blocks)`]{#MetaBlocks}
diff --git a/src/Text/Pandoc/Lua/StackInstances.hs b/src/Text/Pandoc/Lua/StackInstances.hs
index 3eb14eba3..ce6dbdb98 100644
--- a/src/Text/Pandoc/Lua/StackInstances.hs
+++ b/src/Text/Pandoc/Lua/StackInstances.hs
@@ -36,17 +36,14 @@ import Control.Applicative ((<|>))
import Foreign.Lua (FromLuaStack (peek), Lua, LuaInteger, LuaNumber, StackIndex,
ToLuaStack (push), Type (..), throwLuaError, tryLua)
import Text.Pandoc.Definition
-import Text.Pandoc.Lua.Util (addValue, adjustIndexBy, getTable,
- pushViaConstructor)
+import Text.Pandoc.Lua.Util (adjustIndexBy, getTable, pushViaConstructor)
import Text.Pandoc.Shared (safeRead)
import qualified Foreign.Lua as Lua
instance ToLuaStack Pandoc where
- push (Pandoc meta blocks) = do
- Lua.newtable
- addValue "blocks" blocks
- addValue "meta" meta
+ push (Pandoc meta blocks) =
+ pushViaConstructor "Pandoc" blocks meta
instance FromLuaStack Pandoc where
peek idx = do
@@ -55,7 +52,8 @@ instance FromLuaStack Pandoc where
return $ Pandoc meta blocks
instance ToLuaStack Meta where
- push (Meta mmap) = push mmap
+ push (Meta mmap) =
+ pushViaConstructor "Meta" mmap
instance FromLuaStack Meta where
peek idx = Meta <$> peek idx