aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua/Marshaling
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2021-10-29 17:08:03 +0200
committerAlbert Krewinkel <albert@zeitkraut.de>2021-10-29 17:08:30 +0200
commitf4d9b443d8b44b802d564a64280cbe9ea89dacc8 (patch)
tree10fe1c4e9986e045c0537eb30901b499b210be91 /src/Text/Pandoc/Lua/Marshaling
parente1cf0ad1bef439da829068b4c5104d81692e860d (diff)
downloadpandoc-f4d9b443d8b44b802d564a64280cbe9ea89dacc8.tar.gz
Lua: use hslua module abstraction where possible
This will make it easier to generate module documentation in the future.
Diffstat (limited to 'src/Text/Pandoc/Lua/Marshaling')
-rw-r--r--src/Text/Pandoc/Lua/Marshaling/AST.hs1
-rw-r--r--src/Text/Pandoc/Lua/Marshaling/Attr.hs50
2 files changed, 28 insertions, 23 deletions
diff --git a/src/Text/Pandoc/Lua/Marshaling/AST.hs b/src/Text/Pandoc/Lua/Marshaling/AST.hs
index 6bb4fd4e0..aabc9e530 100644
--- a/src/Text/Pandoc/Lua/Marshaling/AST.hs
+++ b/src/Text/Pandoc/Lua/Marshaling/AST.hs
@@ -45,6 +45,7 @@ module Text.Pandoc.Lua.Marshaling.AST
, pushCitation
, pushInline
, pushListAttributes
+ , pushMeta
, pushMetaValue
, pushPandoc
) where
diff --git a/src/Text/Pandoc/Lua/Marshaling/Attr.hs b/src/Text/Pandoc/Lua/Marshaling/Attr.hs
index 2f1f2406a..a38bc6ec7 100644
--- a/src/Text/Pandoc/Lua/Marshaling/Attr.hs
+++ b/src/Text/Pandoc/Lua/Marshaling/Attr.hs
@@ -204,26 +204,30 @@ peekAttrTable idx = do
return $ ident `seq` classes `seq` attribs `seq`
(ident, classes, attribs)
-mkAttr :: LuaError e => LuaE e NumResults
-mkAttr = do
- attr <- ltype (nthBottom 1) >>= \case
- TypeString -> forcePeek $ do
- mident <- optional (peekText (nthBottom 1))
- mclass <- optional (peekList peekText (nthBottom 2))
- mattribs <- optional (peekAttribs (nthBottom 3))
- return (fromMaybe "" mident, fromMaybe [] mclass, fromMaybe [] mattribs)
- TypeTable -> forcePeek $ peekAttrTable (nthBottom 1)
- TypeUserdata -> forcePeek $ peekUD typeAttr (nthBottom 1) <|> do
- attrList <- peekUD typeAttributeList (nthBottom 1)
- return ("", [], attrList)
- TypeNil -> pure nullAttr
- TypeNone -> pure nullAttr
- x -> failLua $ "Cannot create Attr from " ++ show x
- pushAttr attr
- return 1
-
-mkAttributeList :: LuaError e => LuaE e NumResults
-mkAttributeList = do
- attribs <- forcePeek $ peekAttribs (nthBottom 1)
- pushUD typeAttributeList attribs
- return 1
+-- | Constructor for 'Attr'.
+mkAttr :: LuaError e => DocumentedFunction e
+mkAttr = defun "Attr"
+ ### (ltype (nthBottom 1) >>= \case
+ TypeString -> forcePeek $ do
+ mident <- optional (peekText (nthBottom 1))
+ mclass <- optional (peekList peekText (nthBottom 2))
+ mattribs <- optional (peekAttribs (nthBottom 3))
+ return ( fromMaybe "" mident
+ , fromMaybe [] mclass
+ , fromMaybe [] mattribs)
+ TypeTable -> forcePeek $ peekAttrTable (nthBottom 1)
+ TypeUserdata -> forcePeek $ peekUD typeAttr (nthBottom 1) <|> do
+ attrList <- peekUD typeAttributeList (nthBottom 1)
+ return ("", [], attrList)
+ TypeNil -> pure nullAttr
+ TypeNone -> pure nullAttr
+ x -> failLua $ "Cannot create Attr from " ++ show x)
+ =#> functionResult pushAttr "Attr" "new Attr object"
+
+-- | Constructor for 'AttributeList'.
+mkAttributeList :: LuaError e => DocumentedFunction e
+mkAttributeList = defun "AttributeList"
+ ### return
+ <#> parameter peekAttribs "table|AttributeList" "attribs" "an attribute list"
+ =#> functionResult (pushUD typeAttributeList) "AttributeList"
+ "new AttributeList object"