Lua: fix peeker for PandocError.

String error messages were incorrectly popped of the stack when
retrieving a PandocError.
This commit is contained in:
Albert Krewinkel
2022-10-16 17:10:00 +02:00
parent 726c54de27
commit 2463477229
2 changed files with 5 additions and 3 deletions
@@ -46,5 +46,7 @@ peekPandocError idx = Lua.retrieving "PandocError" $
liftLua (Lua.ltype idx) >>= \case
Lua.TypeUserdata -> peekUD typePandocError idx
_ -> do
msg <- liftLua $ Lua.state >>= \l -> Lua.liftIO (Lua.popErrorMessage l)
msg <- liftLua $ do
Lua.pushvalue idx
Lua.state >>= \l -> Lua.liftIO (Lua.popErrorMessage l)
return $ PandocLuaError (UTF8.toText msg)
@@ -88,9 +88,9 @@ instance PandocMonad PandocLua where
-- | Retrieve a @'PandocError'@ from the Lua stack.
popPandocError :: LuaE PandocError PandocError
popPandocError = do
errResult <- runPeek $ peekPandocError top
errResult <- runPeek $ peekPandocError top `lastly` pop 1
case resultToEither errResult of
Right x -> return x
Right x -> return x
Left err -> return $ PandocLuaError (T.pack err)
-- | Conversions between Lua errors and 'PandocError' exceptions.