aboutsummaryrefslogtreecommitdiff
path: root/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2025-07-31 11:49:20 +0200
committerJohn MacFarlane <[email protected]>2025-08-01 10:04:14 -0700
commit75aee7a23c96ff31aa9fcb7608891c33a011d6a1 (patch)
tree155da93d4f6b5e262498aba353e6e92447fb2dc9 /pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs
parent57e7d895db367eb09cb4cb31678ac3b5f6dc9ef7 (diff)
Lua: use proper interface functions to access the CommonState.
- The `PANDOC_STATE` is no longer a userdata object, but a table that behaves like the old object. - Log messages in `PANDOC_STATE.log` are now in temporal order.
Diffstat (limited to 'pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs')
-rw-r--r--pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs24
1 files changed, 4 insertions, 20 deletions
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs
index 135591981..b885cae74 100644
--- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs
+++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs
@@ -14,14 +14,9 @@ module Text.Pandoc.Lua.Module.Log
import Data.Version (makeVersion)
import HsLua
-import Text.Pandoc.Class
- ( CommonState (stVerbosity, stLog)
- , PandocMonad (putCommonState, getCommonState)
- , report )
+import Text.Pandoc.Class (report, runSilently)
import Text.Pandoc.Error (PandocError)
-import Text.Pandoc.Logging
- ( Verbosity (ERROR)
- , LogMessage (ScriptingInfo, ScriptingWarning) )
+import Text.Pandoc.Logging (LogMessage (ScriptingInfo, ScriptingWarning))
import Text.Pandoc.Lua.Marshal.List (pushPandocList)
import Text.Pandoc.Lua.Marshal.LogMessage (pushLogMessage)
import Text.Pandoc.Lua.PandocLua (liftPandocLua, unPandocLua)
@@ -92,23 +87,12 @@ documentedModule = Module
-- results of the function call after that.
silence :: LuaE PandocError NumResults
silence = unPandocLua $ do
- -- get current log messages
- origState <- getCommonState
- let origLog = stLog origState
- let origVerbosity = stVerbosity origState
- putCommonState (origState { stLog = [], stVerbosity = ERROR })
-
-- call function given as the first argument
- liftPandocLua $ do
+ ((), messages) <- runSilently . liftPandocLua $ do
nargs <- (NumArgs . subtract 1 . fromStackIndex) <$> gettop
call @PandocError nargs multret
- -- restore original log messages
- newState <- getCommonState
- let newLog = stLog newState
- putCommonState (newState { stLog = origLog, stVerbosity = origVerbosity })
-
liftPandocLua $ do
- pushPandocList pushLogMessage newLog
+ pushPandocList pushLogMessage messages
insert 1
(NumResults . fromStackIndex) <$> gettop