From be6ec92608b99833d22384e2cd1997491c2743f6 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Sun, 12 Mar 2023 18:06:07 +0100 Subject: Lua: allow to get the JSON encoding of log messages --- pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/CommonState.hs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pandoc-lua-engine/src/Text') diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/CommonState.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/CommonState.hs index 28cb5925b..376f2dd74 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/CommonState.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/CommonState.hs @@ -19,6 +19,7 @@ import HsLua import Text.Pandoc.Class (CommonState (..)) import Text.Pandoc.Logging (LogMessage, showLogMessage) import Text.Pandoc.Lua.Marshal.List (pushPandocList) +import qualified Data.Aeson as Aeson -- | Lua type used for the @CommonState@ object. typeCommonState :: LuaError e => DocumentedType e CommonState @@ -64,5 +65,9 @@ typeLogMessage = deftype "pandoc LogMessage" ### liftPure showLogMessage <#> udparam typeLogMessage "msg" "object" =#> functionResult pushText "string" "stringified log message" + , operation (CustomOperation "__tojson") $ lambda + ### liftPure Aeson.encode + <#> udparam typeLogMessage "msg" "object" + =#> functionResult pushLazyByteString "string" "JSON encoded object" ] mempty -- no members -- cgit v1.2.3