aboutsummaryrefslogtreecommitdiff
path: root/pandoc-lua-engine/src
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2024-06-01 20:56:11 +0200
committerAlbert Krewinkel <[email protected]>2024-06-01 21:10:29 +0200
commit83de55bb357f66984edaf1cd699402dbe4cde5c0 (patch)
treeace4cb05a91d2b5cb9b75c1eabee68f97923f2bc /pandoc-lua-engine/src
parent075ed1052f1739a96317b692b5aa61c03e6ac833 (diff)
Lua: Set `pandoc.List` as default metatable for JSON lists
Lists created by `pandoc.json.decode` now behave like lists generated via `pandoc.List`. This also ensures that `pandoc.List` tables are encoded as JSON arrays when passed to `pandoc.json.encode`. Fixes: #9834
Diffstat (limited to 'pandoc-lua-engine/src')
-rw-r--r--pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs
index e0dd830b2..1e2b628fd 100644
--- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs
+++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs
@@ -28,7 +28,7 @@ import Text.Pandoc.Data (readDataFile)
import Text.Pandoc.Error (PandocError (PandocLuaError))
import Text.Pandoc.Logging (LogMessage (ScriptingWarning))
import Text.Pandoc.Lua.Global (Global (..), setGlobals)
-import Text.Pandoc.Lua.Marshal.List (newListMetatable, pushListModule)
+import Text.Pandoc.Lua.Marshal.List (pushPandocList, pushListModule)
import Text.Pandoc.Lua.PandocLua (PandocLua (..), liftPandocLua)
import Text.Pandoc.Lua.SourcePos (luaSourcePos)
import qualified Data.ByteString.Char8 as Char8
@@ -120,8 +120,8 @@ initLuaState :: PandocLua ()
initLuaState = do
liftPandocLua Lua.openlibs
setWarnFunction
- initJsonMetatable
initPandocModule
+ initJsonMetatable
installLpegSearcher
setGlobalModules
loadInitScript "init.lua"
@@ -210,7 +210,9 @@ initLuaState = do
-- from/via JSON arrays.
initJsonMetatable :: PandocLua ()
initJsonMetatable = liftPandocLua $ do
- newListMetatable HsLua.Aeson.jsonarray (pure ())
+ pushPandocList (const pushnil) []
+ getmetatable top
+ setfield registryindex HsLua.Aeson.jsonarray
Lua.pop 1
-- | Evaluate a @'PandocLua'@ computation, running all contained Lua