summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2017-04-14 10:43:44 +0200
committerAlbert Krewinkel <albert@zeitkraut.de>2017-04-14 11:21:12 +0200
commit0516b5127c3674786f92c61f4131428ed3b8bd4b (patch)
tree129e950e54aa13e49324cb271886f2c3fc2f25fa
parent540a3e80ad33cb43d23532515757dff7ee68a17f (diff)
Drop dependency on hslua-aeson
Pushing values to the lua stack via custom functions is faster and more flexible.
-rw-r--r--pandoc.cabal1
-rw-r--r--src/Text/Pandoc/Lua.hs33
-rw-r--r--src/Text/Pandoc/Lua/StackInstances.hs1
-rw-r--r--stack.full.yaml1
-rw-r--r--stack.pkg.yaml1
-rw-r--r--stack.yaml1
6 files changed, 15 insertions, 23 deletions
diff --git a/pandoc.cabal b/pandoc.cabal
index ef3f8fd04..27ccdb15b 100644
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -300,7 +300,6 @@ Library
pandoc-types >= 1.17 && < 1.18,
aeson >= 0.7 && < 1.2,
aeson-pretty >= 0.8 && < 0.9,
- hslua-aeson >= 0.1.0.2 && < 1,
tagsoup >= 0.13.7 && < 0.15,
base64-bytestring >= 0.1 && < 1.1,
zlib >= 0.5 && < 0.7,
diff --git a/src/Text/Pandoc/Lua.hs b/src/Text/Pandoc/Lua.hs
index 95bc1ef35..bca6a2589 100644
--- a/src/Text/Pandoc/Lua.hs
+++ b/src/Text/Pandoc/Lua.hs
@@ -33,23 +33,20 @@ module Text.Pandoc.Lua ( runLuaFilter, pushPandocModule ) where
import Control.Monad ( (>=>), when )
import Control.Monad.Trans ( MonadIO(..) )
-import Data.HashMap.Lazy ( HashMap )
-import Data.Text ( Text, pack, unpack )
-import Data.Text.Encoding ( decodeUtf8 )
+import Data.Map ( Map )
import Scripting.Lua ( LuaState, StackValue(..) )
-import Scripting.Lua.Aeson ( newstate )
import Text.Pandoc.Definition ( Block(..), Inline(..), Pandoc(..) )
import Text.Pandoc.Lua.PandocModule ( pushPandocModule )
import Text.Pandoc.Lua.StackInstances ()
import Text.Pandoc.Walk
-import qualified Data.HashMap.Lazy as HashMap
+import qualified Data.Map as Map
import qualified Scripting.Lua as Lua
runLuaFilter :: (MonadIO m)
=> FilePath -> [String] -> Pandoc -> m Pandoc
runLuaFilter filterPath args pd = liftIO $ do
- lua <- newstate
+ lua <- Lua.newstate
Lua.openlibs lua
-- create table in registry to store filter functions
Lua.push lua ("PANDOC_FILTER_FUNCTIONS"::String)
@@ -61,12 +58,12 @@ runLuaFilter filterPath args pd = liftIO $ do
status <- Lua.loadfile lua filterPath
if (status /= 0)
then do
- luaErrMsg <- unpack . decodeUtf8 <$> Lua.tostring lua 1
+ Just luaErrMsg <- Lua.peek lua 1
error luaErrMsg
else do
Lua.call lua 0 1
Just luaFilters <- Lua.peek lua (-1)
- Lua.push lua (map pack args)
+ Lua.push lua args
Lua.setglobal lua "PandocParameters"
doc <- runAll luaFilters >=> luaFilter lua "filter_doc" $ pd
Lua.close lua
@@ -89,28 +86,28 @@ walkMWithLuaFilter (LuaFilter lua inlineFnMap blockFnMap docFnMap) =
walkM (execBlockLuaFilter lua blockFnMap) >=>
walkM (execDocLuaFilter lua docFnMap)
-type InlineFunctionMap = HashMap Text (LuaFilterFunction Inline)
-type BlockFunctionMap = HashMap Text (LuaFilterFunction Block)
-type DocFunctionMap = HashMap Text (LuaFilterFunction Pandoc)
+type InlineFunctionMap = Map String (LuaFilterFunction Inline)
+type BlockFunctionMap = Map String (LuaFilterFunction Block)
+type DocFunctionMap = Map String (LuaFilterFunction Pandoc)
data LuaFilter =
LuaFilter LuaState InlineFunctionMap BlockFunctionMap DocFunctionMap
newtype LuaFilterFunction a = LuaFilterFunction { functionIndex :: Int }
execDocLuaFilter :: LuaState
- -> HashMap Text (LuaFilterFunction Pandoc)
+ -> Map String (LuaFilterFunction Pandoc)
-> Pandoc -> IO Pandoc
execDocLuaFilter lua fnMap x = do
let docFnName = "Doc"
- case HashMap.lookup docFnName fnMap of
+ case Map.lookup docFnName fnMap of
Nothing -> return x
Just fn -> runLuaFilterFunction lua fn x
execBlockLuaFilter :: LuaState
- -> HashMap Text (LuaFilterFunction Block)
+ -> Map String (LuaFilterFunction Block)
-> Block -> IO Block
execBlockLuaFilter lua fnMap x = do
- let filterOrId constr = case HashMap.lookup constr fnMap of
+ let filterOrId constr = case Map.lookup constr fnMap of
Nothing -> return x
Just fn -> runLuaFilterFunction lua fn x
case x of
@@ -130,14 +127,14 @@ execBlockLuaFilter lua fnMap x = do
Null -> filterOrId "Null"
execInlineLuaFilter :: LuaState
- -> HashMap Text (LuaFilterFunction Inline)
+ -> Map String (LuaFilterFunction Inline)
-> Inline -> IO Inline
execInlineLuaFilter lua fnMap x = do
let runFn :: PushViaFilterFunction Inline a => LuaFilterFunction Inline -> a
runFn fn = runLuaFilterFunction lua fn
- let tryFilter :: Text -> (LuaFilterFunction Inline -> IO Inline) -> IO Inline
+ let tryFilter :: String -> (LuaFilterFunction Inline -> IO Inline) -> IO Inline
tryFilter fnName callFilterFn =
- case HashMap.lookup fnName fnMap of
+ case Map.lookup fnName fnMap of
Nothing -> return x
Just fn -> callFilterFn fn
case x of
diff --git a/src/Text/Pandoc/Lua/StackInstances.hs b/src/Text/Pandoc/Lua/StackInstances.hs
index bafe24201..38f392527 100644
--- a/src/Text/Pandoc/Lua/StackInstances.hs
+++ b/src/Text/Pandoc/Lua/StackInstances.hs
@@ -41,7 +41,6 @@ import Scripting.Lua
, call, getglobal2, gettable, ltype, newtable, next, objlen
, pop, pushnil, rawgeti, rawseti, settable
)
-import Scripting.Lua.Aeson ()
import Text.Pandoc.Definition
import qualified Data.Map as M
diff --git a/stack.full.yaml b/stack.full.yaml
index bf1d1581d..ac06d7f18 100644
--- a/stack.full.yaml
+++ b/stack.full.yaml
@@ -24,5 +24,4 @@ extra-deps:
- doctemplates-0.1.0.2
- skylighting-0.3.1
- hslua-0.5.0
-- hslua-aeson-0.1.0.3
resolver: lts-8.4
diff --git a/stack.pkg.yaml b/stack.pkg.yaml
index a240a99b9..ad9490c82 100644
--- a/stack.pkg.yaml
+++ b/stack.pkg.yaml
@@ -19,6 +19,5 @@ packages:
extra-dep: false
extra-deps:
- hslua-0.5.0
-- hslua-aeson-0.1.0.3
- skylighting-0.3.2
resolver: lts-8.8
diff --git a/stack.yaml b/stack.yaml
index 965650226..a77d0c7a8 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -9,7 +9,6 @@ packages:
- '.'
extra-deps:
- hslua-0.5.0
-- hslua-aeson-0.1.0.3
- skylighting-0.3.2
- foundation-0.0.6
resolver: lts-8.8