From 0f7653cd10deeeeb646809f9210a46087ff6e4c7 Mon Sep 17 00:00:00 2001
From: Albert Krewinkel <albert@zeitkraut.de>
Date: Thu, 23 Feb 2023 11:22:50 +0100
Subject: [PATCH] Switch to hslua-2.3

---
 pandoc-cli/pandoc-cli.cabal                   |  2 +-
 pandoc-lua-engine/pandoc-lua-engine.cabal     | 22 +++++++++----------
 .../src/Text/Pandoc/Lua/Custom.hs             |  4 +---
 .../src/Text/Pandoc/Lua/Filter.hs             |  2 +-
 pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs |  1 -
 .../src/Text/Pandoc/Lua/Module/CLI.hs         |  2 ++
 .../src/Text/Pandoc/Lua/Module/Format.hs      |  1 +
 .../src/Text/Pandoc/Lua/Module/JSON.hs        |  2 ++
 .../src/Text/Pandoc/Lua/Module/MediaBag.hs    |  1 +
 .../src/Text/Pandoc/Lua/Module/Pandoc.hs      | 10 +++++++++
 .../src/Text/Pandoc/Lua/Module/Scaffolding.hs |  2 ++
 .../src/Text/Pandoc/Lua/Module/Structure.hs   |  1 +
 .../src/Text/Pandoc/Lua/Module/System.hs      |  1 +
 .../src/Text/Pandoc/Lua/Module/Template.hs    |  3 ++-
 .../src/Text/Pandoc/Lua/Module/Types.hs       |  1 +
 .../src/Text/Pandoc/Lua/Module/Utils.hs       |  1 +
 16 files changed, 37 insertions(+), 19 deletions(-)

Index: b/pandoc-lua-engine.cabal
===================================================================
--- a/pandoc-lua-engine.cabal
+++ b/pandoc-lua-engine.cabal
@@ -102,16 +102,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     && < 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.0     && < 3.1
                      , pandoc-lua-marshal    >= 0.2     && < 0.3
@@ -131,13 +129,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
Index: b/src/Text/Pandoc/Lua/Custom.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Custom.hs
+++ b/src/Text/Pandoc/Lua/Custom.hs
@@ -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
 
Index: b/src/Text/Pandoc/Lua/Filter.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Filter.hs
+++ b/src/Text/Pandoc/Lua/Filter.hs
@@ -34,7 +34,7 @@ import Text.Pandoc.Error (PandocError (P
 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
Index: b/src/Text/Pandoc/Lua/Init.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Init.hs
+++ b/src/Text/Pandoc/Lua/Init.hs
@@ -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))
Index: b/src/Text/Pandoc/Lua/Module/CLI.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Module/CLI.hs
+++ b/src/Text/Pandoc/Lua/Module/CLI.hs
@@ -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 =
Index: b/src/Text/Pandoc/Lua/Module/Format.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Module/Format.hs
+++ b/src/Text/Pandoc/Lua/Module/Format.hs
@@ -30,6 +30,7 @@ documentedModule = Module
   , moduleFields = []
   , moduleOperations = []
   , moduleFunctions = functions
+  , moduleTypeInitializers = []
   }
 
 -- | Extension module functions.
Index: b/src/Text/Pandoc/Lua/Module/MediaBag.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Module/MediaBag.hs
+++ b/src/Text/Pandoc/Lua/Module/MediaBag.hs
@@ -53,6 +53,7 @@ documentedModule = Module
       , write
       ]
   , moduleOperations = []
+  , moduleTypeInitializers = []
   }
 
 -- | Delete a single item from the media bag.
Index: b/src/Text/Pandoc/Lua/Module/Pandoc.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Module/Pandoc.hs
+++ b/src/Text/Pandoc/Lua/Module/Pandoc.hs
@@ -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
         }
Index: b/src/Text/Pandoc/Lua/Module/Scaffolding.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Module/Scaffolding.hs
+++ b/src/Text/Pandoc/Lua/Module/Scaffolding.hs
@@ -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"
Index: b/src/Text/Pandoc/Lua/Module/Structure.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Module/Structure.hs
+++ b/src/Text/Pandoc/Lua/Module/Structure.hs
@@ -51,6 +51,7 @@ documentedModule = Module
       , table_of_contents
       ]
   , moduleOperations = []
+  , moduleTypeInitializers = []
   }
 
 make_sections :: LuaError e => DocumentedFunction e
Index: b/src/Text/Pandoc/Lua/Module/System.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Module/System.hs
+++ b/src/Text/Pandoc/Lua/Module/System.hs
@@ -38,4 +38,5 @@ documentedModule = Module
       , setName "with_working_directory" with_wd
       ]
   , moduleOperations = []
+  , moduleTypeInitializers = []
   }
Index: b/src/Text/Pandoc/Lua/Module/Template.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Module/Template.hs
+++ b/src/Text/Pandoc/Lua/Module/Template.hs
@@ -16,7 +16,7 @@ import HsLua.Module.DocLayout (peekDoc,
 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.
Index: b/src/Text/Pandoc/Lua/Module/Types.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Module/Types.hs
+++ b/src/Text/Pandoc/Lua/Module/Types.hs
@@ -39,4 +39,5 @@ documentedModule = Module
         =#> functionResult pushVersion "Version" "A new Version object."
       ]
   , moduleOperations = []
+  , moduleTypeInitializers = []
   }
Index: b/src/Text/Pandoc/Lua/Module/Utils.hs
===================================================================
--- a/src/Text/Pandoc/Lua/Module/Utils.hs
+++ b/src/Text/Pandoc/Lua/Module/Utils.hs
@@ -49,6 +49,7 @@ documentedModule = Module
   , moduleDescription = "pandoc utility functions"
   , moduleFields = []
   , moduleOperations = []
+  , moduleTypeInitializers = []
   , moduleFunctions =
     [ defun "blocks_to_inlines"
       ### (\blks mSep -> do
