Switch to hslua-2.3

This commit is contained in:
Albert Krewinkel
2023-03-13 13:23:43 +01:00
parent 7916940c23
commit 0f7653cd10
16 changed files with 37 additions and 19 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ executable pandoc
hs-source-dirs: no-server
if flag(lua)
build-depends: hslua-cli >= 1.2 && < 1.3,
build-depends: hslua-cli >= 1.3 && < 1.4,
pandoc-lua-engine >= 0.1 && < 0.2
hs-source-dirs: lua
else
+10 -12
View File
@@ -104,16 +104,14 @@ library
, doclayout >= 0.4 && < 0.5
, doctemplates >= 0.11 && < 0.12
, exceptions >= 0.8 && < 0.11
, hslua >= 2.2.1 && < 2.3
, hslua-aeson >= 2.2.1 && < 2.3
, hslua-core >= 2.2.1 && < 2.3
, hslua-module-doclayout>= 1.0.4 && < 1.1
, hslua-module-path >= 1.0.3 && < 1.1
, hslua-module-system >= 1.0.3 && < 1.1
, hslua-module-text >= 1.0.3 && < 1.1
, hslua-module-version >= 1.0.3 && < 1.1
, hslua-module-zip >= 1.0.0 && < 1.1
, lpeg >= 1.0.1 && < 1.1
, hslua >= 2.3 && < 2.4
, hslua-module-doclayout>= 1.1 && < 1.2
, hslua-module-path >= 1.1 && < 1.2
, hslua-module-system >= 1.1 && < 1.2
, hslua-module-text >= 1.1 && < 1.2
, hslua-module-version >= 1.1 && < 1.2
, hslua-module-zip >= 1.1 && < 1.2
, lpeg >= 1.0.4 && < 1.1
, mtl >= 2.2 && < 2.4
, pandoc >= 3.1 && < 3.2
, pandoc-lua-marshal >= 0.2.1 && < 0.3
@@ -133,13 +131,13 @@ test-suite test-pandoc-lua-engine
, data-default
, exceptions >= 0.8 && < 0.11
, filepath
, hslua >= 2.1 && < 2.3
, hslua >= 2.3 && < 2.4
, pandoc
, pandoc-types >= 1.22 && < 1.24
, tasty
, tasty-golden
, tasty-hunit
, tasty-lua >= 1.0 && < 1.1
, tasty-lua >= 1.1 && < 1.2
, text >= 1.1.1 && < 2.1
other-modules: Tests.Lua
, Tests.Lua.Module
@@ -1,7 +1,6 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TupleSections #-}
{- |
Module : Text.Pandoc.Lua.Custom
Copyright : © 2021-2023 Albert Krewinkel, John MacFarlane
@@ -16,7 +15,6 @@ import Control.Monad ((<=<), (<$!>))
import Control.Monad.IO.Class (MonadIO)
import Data.Maybe (fromMaybe)
import HsLua as Lua hiding (Operation (Div))
import HsLua.Core.Run (GCManagedState, newGCManagedState, withGCManagedState)
import Text.Pandoc.Class (PandocMonad, findFileWithDataFallback)
import Text.Pandoc.Error (PandocError)
import Text.Pandoc.Lua.Global (Global (..), setGlobals)
@@ -40,7 +38,7 @@ loadCustom luaFile = do
either throw pure <=< runLuaWith luaState $ do
let globals = [ PANDOC_SCRIPT_FILE luaFile ]
setGlobals globals
dofileTrace luaFile' >>= \case
dofileTrace (Just luaFile') >>= \case
OK -> pure ()
_ -> throwErrorAsException
@@ -34,7 +34,7 @@ import Text.Pandoc.Error (PandocError (PandocFilterError, PandocLuaError))
runFilterFile :: FilePath -> Pandoc -> LuaE PandocError Pandoc
runFilterFile filterPath doc = do
oldtop <- gettop
stat <- dofileTrace filterPath
stat <- dofileTrace (Just filterPath)
if stat /= Lua.OK
then throwErrorAsException
else do
@@ -22,7 +22,6 @@ import Control.Monad.Catch (throwM, try)
import Control.Monad.Trans (MonadIO (..))
import Data.Maybe (catMaybes)
import HsLua as Lua hiding (status, try)
import HsLua.Core.Run as Lua
import Text.Pandoc.Class (PandocMonad (..))
import Text.Pandoc.Data (readDataFile)
import Text.Pandoc.Error (PandocError (PandocLuaError))
@@ -31,6 +31,7 @@ documentedModule = Module
, moduleFields =
[ Field
{ fieldName = "default_options"
, fieldType = "table"
, fieldDescription = "Default CLI options, using a JSON-like " <>
"representation."
, fieldPushValue = pushViaJSON defaultOpts
@@ -50,6 +51,7 @@ documentedModule = Module
]
]
, moduleOperations = []
, moduleTypeInitializers = []
}
where
peekArgs idx =
@@ -30,6 +30,7 @@ documentedModule = Module
, moduleFields = []
, moduleOperations = []
, moduleFunctions = functions
, moduleTypeInitializers = []
}
-- | Extension module functions.
@@ -42,6 +42,7 @@ documentedModule = Module
, moduleFields = fields
, moduleFunctions = functions
, moduleOperations = []
, moduleTypeInitializers = []
}
--
@@ -58,6 +59,7 @@ fields =
null :: LuaError e => Field e
null = Field
{ fieldName = "null"
, fieldType = "userdata"
, fieldDescription = "Value used to represent the `null` JSON value."
, fieldPushValue = pushValue Aeson.Null
}
@@ -53,6 +53,7 @@ documentedModule = Module
, write
]
, moduleOperations = []
, moduleTypeInitializers = []
}
-- | Delete a single item from the media bag.
@@ -74,12 +74,18 @@ documentedModule = Module
, inlineConstructors
, metaValueConstructors
]
, moduleTypeInitializers =
[ initType typePandoc
, initType typeBlock
, initType typeInline
]
}
-- | Set of input formats accepted by @read@.
readersField :: Field PandocError
readersField = Field
{ fieldName = "readers"
, fieldType = "table"
, fieldDescription = T.unlines
[ "Set of formats that pandoc can parse. All keys in this table can"
, "be used as the `format` value in `pandoc.read`."
@@ -92,6 +98,7 @@ readersField = Field
writersField :: Field PandocError
writersField = Field
{ fieldName = "writers"
, fieldType = "table"
, fieldDescription = T.unlines
[ "Set of formats that pandoc can generate. All keys in this table"
, "can be used as the `format` value in `pandoc.write`."
@@ -104,6 +111,7 @@ writersField = Field
inlineField :: Field PandocError
inlineField = Field
{ fieldName = "Inline"
, fieldType = "table"
, fieldDescription = "Inline constructors, nested under 'constructors'."
-- the nesting happens for historical reasons and should probably be
-- changed.
@@ -114,6 +122,7 @@ inlineField = Field
blockField :: Field PandocError
blockField = Field
{ fieldName = "Block"
, fieldType = "table"
, fieldDescription = "Inline constructors, nested under 'constructors'."
-- the nesting happens for historical reasons and should probably be
-- changed.
@@ -176,6 +185,7 @@ stringConstants =
]
toField s = Field
{ fieldName = T.pack s
, fieldType = "string"
, fieldDescription = T.pack s
, fieldPushValue = pushString s
}
@@ -26,12 +26,14 @@ documentedModule = Module
, moduleFields = [writerScaffolding]
, moduleOperations = []
, moduleFunctions = []
, moduleTypeInitializers = []
}
-- | Template module functions.
writerScaffolding :: Field PandocError
writerScaffolding = Field
{ fieldName = "Writer"
, fieldType = "table"
, fieldDescription = T.unlines
[ "An object to be used as a `Writer` function; the construct handles"
, "most of the boilerplate, expecting only render functions for all"
@@ -51,6 +51,7 @@ documentedModule = Module
, table_of_contents
]
, moduleOperations = []
, moduleTypeInitializers = []
}
make_sections :: LuaError e => DocumentedFunction e
@@ -41,4 +41,5 @@ documentedModule = Module
, setName "with_working_directory" with_wd
]
, moduleOperations = []
, moduleTypeInitializers = []
}
@@ -16,7 +16,7 @@ import HsLua.Module.DocLayout (peekDoc, pushDoc)
import Text.Pandoc.Error (PandocError)
import Text.Pandoc.Lua.Marshal.AST (peekMeta, pushBlocks, pushInlines)
import Text.Pandoc.Lua.Marshal.Context (peekContext, pushContext)
import Text.Pandoc.Lua.Marshal.Template (peekTemplate, pushTemplate)
import Text.Pandoc.Lua.Marshal.Template (typeTemplate, peekTemplate, pushTemplate)
import Text.Pandoc.Lua.PandocLua (PandocLua (unPandocLua), liftPandocLua)
import Text.Pandoc.Writers.Shared (metaToContext')
import Text.Pandoc.Templates
@@ -35,6 +35,7 @@ documentedModule = Module
, moduleFields = []
, moduleOperations = []
, moduleFunctions = functions
, moduleTypeInitializers = [initType typeTemplate]
}
-- | Template module functions.
@@ -39,4 +39,5 @@ documentedModule = Module
=#> functionResult pushVersion "Version" "A new Version object."
]
, moduleOperations = []
, moduleTypeInitializers = []
}
@@ -49,6 +49,7 @@ documentedModule = Module
, moduleDescription = "pandoc utility functions"
, moduleFields = []
, moduleOperations = []
, moduleTypeInitializers = []
, moduleFunctions =
[ defun "blocks_to_inlines"
### (\blks mSep -> do