{- |
   Module      : Text.Pandoc.Lua.Module.System
   Copyright   : © 2019-2021 Albert Krewinkel
   License     : GNU GPL, version 2 or above

   Maintainer  : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
   Stability   : alpha

Pandoc's system Lua module.
-}
module Text.Pandoc.Lua.Module.System
  ( pushModule
  ) where

import Foreign.Lua (Lua, NumResults)
import Foreign.Lua.Module.System (arch, env, getwd, os,
                                  with_env, with_tmpdir, with_wd)
import Text.Pandoc.Lua.Util (addFunction, addField)

import qualified Foreign.Lua as Lua

-- | Push the pandoc.system module on the Lua stack.
pushModule :: Lua NumResults
pushModule :: Lua NumResults
pushModule = do
  Lua ()
Lua.newtable
  String -> String -> Lua ()
forall a. Pushable a => String -> a -> Lua ()
addField String
"arch" String
arch
  String -> String -> Lua ()
forall a. Pushable a => String -> a -> Lua ()
addField String
"os" String
os
  String -> Lua NumResults -> Lua ()
forall a. ToHaskellFunction a => String -> a -> Lua ()
addFunction String
"environment" Lua NumResults
env
  String -> Lua String -> Lua ()
forall a. ToHaskellFunction a => String -> a -> Lua ()
addFunction String
"get_working_directory" Lua String
getwd
  String
-> (Map String String -> Callback -> Lua NumResults) -> Lua ()
forall a. ToHaskellFunction a => String -> a -> Lua ()
addFunction String
"with_environment" Map String String -> Callback -> Lua NumResults
with_env
  String
-> (String -> AnyValue -> Optional Callback -> Lua NumResults)
-> Lua ()
forall a. ToHaskellFunction a => String -> a -> Lua ()
addFunction String
"with_temporary_directory" String -> AnyValue -> Optional Callback -> Lua NumResults
with_tmpdir
  String -> (String -> Callback -> Lua NumResults) -> Lua ()
forall a. ToHaskellFunction a => String -> a -> Lua ()
addFunction String
"with_working_directory" String -> Callback -> Lua NumResults
with_wd
  NumResults -> Lua NumResults
forall (m :: * -> *) a. Monad m => a -> m a
return NumResults
1