    {-# LANGUAGE OverloadedStrings    #-}
    {- |
       Module      : Text.Pandoc.Lua.Marshal.CommonState
       Copyright   : © 2012-2024 John MacFarlane
                     © 2017-2024 Albert Krewinkel
       License     : GNU GPL, version 2 or above
       Maintainer  : Albert Krewinkel <albert+pandoc@tarleb.com>
       Stability   : alpha

    Instances to marshal (push) and unmarshal (peek) the common state.
    -}
    module Text.Pandoc.Lua.Marshal.CommonState
      ( typeCommonState
      , peekCommonState
      , pushCommonState
      ) where

    import HsLua
    import Text.Pandoc.Class (CommonState)

    -- | Lua type used for the @CommonState@ object.
    --
    -- This is an opaque value that is required for the Lua interpreter
    -- to become an instance of "PandocMonad".
    --
    typeCommonState :: LuaError e => DocumentedType e CommonState
    typeCommonState :: forall e. LuaError e => DocumentedType e CommonState
    typeCommonState = Name
    -> [(Operation, DocumentedFunction e)]
    -> [Member e (DocumentedFunction e) CommonState]
    -> DocumentedType e CommonState
    forall e a.
    LuaError e =>
    Name
    -> [(Operation, DocumentedFunction e)]
    -> [Member e (DocumentedFunction e) a]
    -> DocumentedType e a
    deftype Name
    "CommonState" [] []

    -- | Retrieves the common state from Lua
    peekCommonState :: LuaError e => Peeker e CommonState
    peekCommonState :: forall e. LuaError e => Peeker e CommonState
    peekCommonState = DocumentedTypeWithList e CommonState (ZonkAny 0)
    -> Peeker e CommonState
    forall e a itemtype.
    LuaError e =>
    DocumentedTypeWithList e a itemtype -> Peeker e a
    peekUD DocumentedTypeWithList e CommonState (ZonkAny 0)
    forall e. LuaError e => DocumentedType e CommonState
    typeCommonState

    -- | Pushes the common pandoc state to the Lua stack.
    pushCommonState :: LuaError e => Pusher e CommonState
    pushCommonState :: forall e. LuaError e => Pusher e CommonState
    pushCommonState = DocumentedTypeWithList e CommonState (ZonkAny 1)
    -> CommonState -> LuaE e ()
    forall e a itemtype.
    LuaError e =>
    DocumentedTypeWithList e a itemtype -> a -> LuaE e ()
    pushUD DocumentedTypeWithList e CommonState (ZonkAny 1)
    forall e. LuaError e => DocumentedType e CommonState
    typeCommonState