From b5b9edf5645277c11fd9d3a9300c74a7f08434f5 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Wed, 15 Mar 2023 20:49:49 +0100 Subject: Lua: keep the Lua stack clean A metatable used during initialization was not properly removed from the stack. Likewise, accessing the CommonState from Lua previously led to the pollution of the Lua stack with a left-over value. --- pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs | 1 + pandoc-lua-engine/src/Text/Pandoc/Lua/PandocLua.hs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'pandoc-lua-engine/src') diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs index aa501fbaf..247b70add 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs @@ -188,6 +188,7 @@ initLuaState = do initJsonMetatable :: PandocLua () initJsonMetatable = liftPandocLua $ do newListMetatable HsLua.Aeson.jsonarray (pure ()) + Lua.pop 1 -- | Evaluate a @'PandocLua'@ computation, running all contained Lua -- operations. diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/PandocLua.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/PandocLua.hs index 111674f87..c3f8139dd 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/PandocLua.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/PandocLua.hs @@ -78,7 +78,7 @@ instance PandocMonad PandocLua where getCommonState = PandocLua $ do Lua.getglobal "PANDOC_STATE" - forcePeek $ peekCommonState Lua.top + forcePeek $ peekCommonState Lua.top `lastly` pop 1 putCommonState cst = PandocLua $ do pushCommonState cst Lua.setglobal "PANDOC_STATE" -- cgit v1.2.3