diff options
author | John MacFarlane <jgm@berkeley.edu> | 2021-08-22 12:01:28 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2021-08-24 22:17:52 -0700 |
commit | 0df003b099ca16bddee215d6b9f151591f57c6d1 (patch) | |
tree | 069b9c90df61075b5cd8cadcdf3b929881e3fa75 /src/Text/Pandoc/Lua | |
parent | 7ff06a8c43019f56db3e647a55d4d8ec82d2fd62 (diff) | |
download | pandoc-0df003b099ca16bddee215d6b9f151591f57c6d1.tar.gz |
Lua subsystem and custom writers: generalize types from PandocIO...
to any instance of PandocMonad and MonadIO.
This involves an API change, since the type of
runLua is now
(PandocMonad m, MonadIO m) => Lua a -> m (Either PandocError a)
Diffstat (limited to 'src/Text/Pandoc/Lua')
-rw-r--r-- | src/Text/Pandoc/Lua/Init.hs | 5 | ||||
-rw-r--r-- | src/Text/Pandoc/Lua/PandocLua.hs | 5 |
2 files changed, 4 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Lua/Init.hs b/src/Text/Pandoc/Lua/Init.hs index baa6f0295..94691666c 100644 --- a/src/Text/Pandoc/Lua/Init.hs +++ b/src/Text/Pandoc/Lua/Init.hs @@ -18,8 +18,7 @@ import Control.Monad.Trans (MonadIO (..)) import Data.Data (Data, dataTypeConstrs, dataTypeOf, showConstr) import Foreign.Lua (Lua) import GHC.IO.Encoding (getForeignEncoding, setForeignEncoding, utf8) -import Text.Pandoc.Class.PandocMonad (readDataFile) -import Text.Pandoc.Class.PandocIO (PandocIO) +import Text.Pandoc.Class.PandocMonad (readDataFile, PandocMonad) import Text.Pandoc.Error (PandocError) import Text.Pandoc.Lua.Packages (installPandocPackageSearcher) import Text.Pandoc.Lua.PandocLua (PandocLua, liftPandocLua, runPandocLua) @@ -30,7 +29,7 @@ import qualified Text.Pandoc.Lua.Module.Pandoc as ModulePandoc -- | Run the lua interpreter, using pandoc's default way of environment -- initialization. -runLua :: Lua a -> PandocIO (Either PandocError a) +runLua :: (PandocMonad m, MonadIO m) => Lua a -> m (Either PandocError a) runLua luaOp = do enc <- liftIO $ getForeignEncoding <* setForeignEncoding utf8 res <- runPandocLua . try $ do diff --git a/src/Text/Pandoc/Lua/PandocLua.hs b/src/Text/Pandoc/Lua/PandocLua.hs index 750e019b6..3f6641f95 100644 --- a/src/Text/Pandoc/Lua/PandocLua.hs +++ b/src/Text/Pandoc/Lua/PandocLua.hs @@ -30,7 +30,6 @@ import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow) import Control.Monad.Except (MonadError (catchError, throwError)) import Control.Monad.IO.Class (MonadIO (liftIO)) import Foreign.Lua (Lua (..), NumResults, Pushable, ToHaskellFunction) -import Text.Pandoc.Class.PandocIO (PandocIO) import Text.Pandoc.Class.PandocMonad (PandocMonad (..), readDefaultDataFile) import Text.Pandoc.Error (PandocError (PandocLuaError)) import Text.Pandoc.Lua.Global (Global (..), setGlobals) @@ -59,7 +58,7 @@ liftPandocLua = PandocLua -- | Evaluate a @'PandocLua'@ computation, running all contained Lua -- operations.. -runPandocLua :: PandocLua a -> PandocIO a +runPandocLua :: (PandocMonad m, MonadIO m) => PandocLua a -> m a runPandocLua pLua = do origState <- getCommonState globals <- defaultGlobals @@ -103,7 +102,7 @@ loadDefaultModule name = do throwError $ PandocLuaError (T.pack err) -- | Global variables which should always be set. -defaultGlobals :: PandocIO [Global] +defaultGlobals :: PandocMonad m => m [Global] defaultGlobals = do commonState <- getCommonState return |