diff --git a/pandoc.cabal b/pandoc.cabal index aae415275..3b6640d55 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -540,9 +540,10 @@ library build-depends: template-haskell if flag(lua53) build-depends: hslua >= 2.1 && < 2.2, - hslua-aeson >= 2.1 && < 2.3 + hslua-aeson >= 2.2.1 && < 2.3 else build-depends: hslua >= 2.2.1 && < 2.3 + , hslua-aeson >= 2.2.1 && < 2.3 if flag(embed_data_files) cpp-options: -DEMBED_DATA_FILES other-modules: Text.Pandoc.Data diff --git a/src/Text/Pandoc/Lua/Init.hs b/src/Text/Pandoc/Lua/Init.hs index ab03296ad..966f0a581 100644 --- a/src/Text/Pandoc/Lua/Init.hs +++ b/src/Text/Pandoc/Lua/Init.hs @@ -21,11 +21,12 @@ import Data.Maybe (catMaybes) import HsLua as Lua hiding (status, try) import Text.Pandoc.Class.PandocMonad (PandocMonad, readDataFile) import Text.Pandoc.Error (PandocError (PandocLuaError)) -import Text.Pandoc.Lua.Marshal.List (pushListModule) +import Text.Pandoc.Lua.Marshal.List (newListMetatable, pushListModule) import Text.Pandoc.Lua.PandocLua (PandocLua, liftPandocLua, runPandocLua) import qualified Data.ByteString.Char8 as Char8 import qualified Data.Text as T import qualified Lua.LPeg as LPeg +import qualified HsLua.Aeson import qualified HsLua.Module.DocLayout as Module.Layout import qualified HsLua.Module.Path as Module.Path import qualified HsLua.Module.Text as Module.Text @@ -66,6 +67,7 @@ loadedModules = initLuaState :: PandocLua () initLuaState = do liftPandocLua Lua.openlibs + initJsonMetatable initPandocModule installLpegSearcher setGlobalModules @@ -143,3 +145,9 @@ initLuaState = do Lua.pushHaskellFunction $ Lua.state >>= liftIO . LPeg.lpeg_searcher Lua.rawseti (Lua.nth 2) . (+1) . fromIntegral =<< Lua.rawlen (Lua.nth 2) Lua.pop 1 -- remove 'package.searchers' from stack + +-- | Setup the metatable that's assigned to Lua tables that were created +-- from/via JSON arrays. +initJsonMetatable :: PandocLua () +initJsonMetatable = liftPandocLua $ do + newListMetatable HsLua.Aeson.jsonarray (pure ()) diff --git a/stack.yaml b/stack.yaml index 47b366879..9d006f4f0 100644 --- a/stack.yaml +++ b/stack.yaml @@ -12,7 +12,7 @@ extra-deps: - emojis-0.1.2 - lpeg-1.0.3 - hslua-2.2.1 -- hslua-aeson-2.2.0 +- hslua-aeson-2.2.1 - hslua-classes-2.2.0 - hslua-core-2.2.1 - hslua-marshalling-2.2.1