aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2017-12-18 14:24:16 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2017-12-18 18:10:08 +0100
commit70dc5834da16680caedef4727b1d7f335f0b5427 (patch)
tree3b0d73b5648e9bd9fcdbdc7f1089975140d4d128 /src
parent808f6d3fa1816401d9eb1d6a5d1821fb783cc1d5 (diff)
downloadpandoc-70dc5834da16680caedef4727b1d7f335f0b5427.tar.gz
Lua filters: perform minor code clean-up
Change: minor
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Lua/Init.hs8
-rw-r--r--src/Text/Pandoc/Lua/PandocModule.hs11
2 files changed, 8 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Lua/Init.hs b/src/Text/Pandoc/Lua/Init.hs
index a2bfa3801..9b107e945 100644
--- a/src/Text/Pandoc/Lua/Init.hs
+++ b/src/Text/Pandoc/Lua/Init.hs
@@ -50,8 +50,7 @@ import qualified Foreign.Lua.Module.Text as Lua
-- initalization.
runPandocLua :: Lua a -> PandocIO (Either LuaException a)
runPandocLua luaOp = do
- datadir <- getUserDataDir
- luaPkgParams <- luaPackageParams datadir
+ luaPkgParams <- luaPackageParams
enc <- liftIO $ getForeignEncoding <* setForeignEncoding utf8
res <- liftIO $ Lua.runLuaEither (initLuaState luaPkgParams *> luaOp)
liftIO $ setForeignEncoding enc
@@ -60,9 +59,10 @@ runPandocLua luaOp = do
return res
-- | Generate parameters required to setup pandoc's lua environment.
-luaPackageParams :: Maybe FilePath -> PandocIO LuaPackageParams
-luaPackageParams datadir = do
+luaPackageParams :: PandocIO LuaPackageParams
+luaPackageParams = do
commonState <- getCommonState
+ datadir <- getUserDataDir
mbRef <- liftIO . newIORef =<< getMediaBag
return LuaPackageParams
{ luaPkgCommonState = commonState
diff --git a/src/Text/Pandoc/Lua/PandocModule.hs b/src/Text/Pandoc/Lua/PandocModule.hs
index 75f884c46..6bc2618fd 100644
--- a/src/Text/Pandoc/Lua/PandocModule.hs
+++ b/src/Text/Pandoc/Lua/PandocModule.hs
@@ -71,16 +71,13 @@ pushPandocModule datadir = do
return 1
walkElement :: (ToLuaStack a, Walkable [Inline] a, Walkable [Block] a)
- => a -> LuaFilter -> Lua NumResults
-walkElement x f = do
- x' <- walkInlines f x >>= walkBlocks f
- Lua.push x'
- return 1
+ => a -> LuaFilter -> Lua a
+walkElement x f = walkInlines f x >>= walkBlocks f
-walkInline :: Inline -> LuaFilter -> Lua NumResults
+walkInline :: Inline -> LuaFilter -> Lua Inline
walkInline = walkElement
-walkBlock :: Block -> LuaFilter -> Lua NumResults
+walkBlock :: Block -> LuaFilter -> Lua Block
walkBlock = walkElement
readDoc :: String -> String -> Lua NumResults