git.iko.soy/typeable/pandoc
on master help sign in
Lua/StackInstances: push Pandoc and Meta via constructor

Pandoc and Meta elements are now pushed by calling the respective constructor functions of the pandoc Lua module. This makes serialization consistent with the way blocks and inlines are pushed to lua and allows to use List methods with the `blocks` value.

commit6640506ddc0ab848824d818a363c2e685b8b31a5 authorAlbert Krewinkel <albert@zeitkraut.de> dateFri 1 Dec 2017, 17:58 (9 years ago) parent5026dfa
3 files changed+31−7
data/pandoc.lua+15 doc/lua-filters.md+11 src/Text/Pandoc/Lua/StackInstances.hs+5−7
data/pandoc.lua+15
@@ -152,6 +152,21 @@ end
152152-- DEPRECATED synonym:
153153M.Doc = M.Pandoc
154154
155+------------------------------------------------------------------------
156+-- Meta
157+-- @section Meta
158+
159+--- Create a new Meta object. It sets the metatable of the given table to
160+--- `Meta`.
161+-- @function Meta
162+-- @tparam meta table table containing document meta information
163+M.Meta = {}
164+M.Meta.__call = function(t, meta)
165+ return setmetatable(meta, self)
166+end
167+setmetatable(M.Meta, M.Meta)
168+
169+
155170------------------------------------------------------------------------
156171-- MetaValue
157172-- @section MetaValue
doc/lua-filters.md+11
@@ -617,6 +617,17 @@ Lua functions for pandoc scripts.
617617 `meta`:
618618 : document meta data
619619
620+## Meta
621+
622+[`Meta (table)`]{#Meta}
623+
624+: Create a new Meta object.
625+
626+ Parameters:
627+
628+ `table`:
629+ : table containing document meta information
630+
620631## MetaValue
621632
622633[`MetaBlocks (blocks)`]{#MetaBlocks}
src/Text/Pandoc/Lua/StackInstances.hs+5−7
@@ -36,17 +36,14 @@ import Control.Applicative ((<|>))
3636import Foreign.Lua (FromLuaStack (peek), Lua, LuaInteger, LuaNumber, StackIndex,
3737 ToLuaStack (push), Type (..), throwLuaError, tryLua)
3838import Text.Pandoc.Definition
39−import Text.Pandoc.Lua.Util (addValue, adjustIndexBy, getTable,
40− pushViaConstructor)
39+import Text.Pandoc.Lua.Util (adjustIndexBy, getTable, pushViaConstructor)
4140import Text.Pandoc.Shared (safeRead)
4241
4342import qualified Foreign.Lua as Lua
4443
4544instance ToLuaStack Pandoc where
46− push (Pandoc meta blocks) = do
47− Lua.newtable
48− addValue "blocks" blocks
49− addValue "meta" meta
45+ push (Pandoc meta blocks) =
46+ pushViaConstructor "Pandoc" blocks meta
5047
5148instance FromLuaStack Pandoc where
5249 peek idx = do
@@ -55,7 +52,8 @@ instance FromLuaStack Pandoc where
5552 return $ Pandoc meta blocks
5653
5754instance ToLuaStack Meta where
58− push (Meta mmap) = push mmap
55+ push (Meta mmap) =
56+ pushViaConstructor "Meta" mmap
5957instance FromLuaStack Meta where
6058 peek idx = Meta <$> peek idx
6159