diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2017-08-13 12:37:10 +0200 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2017-08-13 14:23:54 +0200 |
commit | 2dc3dbd68b557cbd8974b9daf84df3d26ab5f843 (patch) | |
tree | acd1e83277f97cddd2e2717da6cb8243c3e4f57e /src/Text/Pandoc/Lua/PandocModule.hs | |
parent | 418bda81282c82325c5a296a3c486fdc5ab1dfe0 (diff) | |
download | pandoc-2dc3dbd68b557cbd8974b9daf84df3d26ab5f843.tar.gz |
Use hslua >= 0.7, update Lua code
Diffstat (limited to 'src/Text/Pandoc/Lua/PandocModule.hs')
-rw-r--r-- | src/Text/Pandoc/Lua/PandocModule.hs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Lua/PandocModule.hs b/src/Text/Pandoc/Lua/PandocModule.hs index d46ed3629..c8eaf3da0 100644 --- a/src/Text/Pandoc/Lua/PandocModule.hs +++ b/src/Text/Pandoc/Lua/PandocModule.hs @@ -31,31 +31,31 @@ import Control.Monad (unless) import Data.ByteString.Char8 (unpack) import Data.Default (Default (..)) import Data.Text (pack) -import Scripting.Lua (LuaState, call, push, pushhsfunction, rawset) +import Foreign.Lua (Lua, Status (OK), liftIO, push, pushHaskellFunction) +import Foreign.Lua.Api (call, loadstring, rawset) import Text.Pandoc.Class import Text.Pandoc.Definition (Pandoc) import Text.Pandoc.Options (ReaderOptions(readerExtensions)) -import Text.Pandoc.Lua.Compat (loadstring) import Text.Pandoc.Lua.StackInstances () import Text.Pandoc.Readers (Reader (..), getReader) -- | Push the "pandoc" on the lua stack. -pushPandocModule :: Maybe FilePath -> LuaState -> IO () -pushPandocModule datadir lua = do - script <- pandocModuleScript datadir - status <- loadstring lua script "pandoc.lua" - unless (status /= 0) $ call lua 0 1 - push lua "__read" - pushhsfunction lua read_doc - rawset lua (-3) +pushPandocModule :: Maybe FilePath -> Lua () +pushPandocModule datadir = do + script <- liftIO (pandocModuleScript datadir) + status <- loadstring script + unless (status /= OK) $ call 0 1 + push "__read" + pushHaskellFunction readDoc + rawset (-3) -- | Get the string representation of the pandoc module pandocModuleScript :: Maybe FilePath -> IO String pandocModuleScript datadir = unpack <$> runIOorExplode (setUserDataDir datadir >> readDataFile "pandoc.lua") -read_doc :: String -> String -> IO (Either String Pandoc) -read_doc formatSpec content = do +readDoc :: String -> String -> Lua (Either String Pandoc) +readDoc formatSpec content = liftIO $ do case getReader formatSpec of Left s -> return $ Left s Right (reader, es) -> |