diff options
| author | Albert Krewinkel <[email protected]> | 2023-03-15 20:49:49 +0100 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2023-03-15 20:57:45 +0100 |
| commit | b5b9edf5645277c11fd9d3a9300c74a7f08434f5 (patch) | |
| tree | a37127f10bda99b6f47fefaf0e1c333fff0dce44 /pandoc-lua-engine | |
| parent | 369e7b52e81735695d206d8f23308f96d39e0986 (diff) | |
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.
Diffstat (limited to 'pandoc-lua-engine')
| -rw-r--r-- | pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs | 1 | ||||
| -rw-r--r-- | pandoc-lua-engine/src/Text/Pandoc/Lua/PandocLua.hs | 2 |
2 files changed, 2 insertions, 1 deletions
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" |
