diff options
Diffstat (limited to 'pandoc-cli/lua/PandocCLI/Lua.hs')
| -rw-r--r-- | pandoc-cli/lua/PandocCLI/Lua.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/pandoc-cli/lua/PandocCLI/Lua.hs b/pandoc-cli/lua/PandocCLI/Lua.hs new file mode 100644 index 000000000..6507587c8 --- /dev/null +++ b/pandoc-cli/lua/PandocCLI/Lua.hs @@ -0,0 +1,35 @@ +{-# LANGUAGE OverloadedStrings #-} +{- | + Module : PandocCLI.Lua + Copyright : © 2022 Albert Krewinkel + License : GPL-2.0-or-later + Maintainer : Albert Krewinkel <albert@zeitkraut.de> + +Functions to run the pandoc Lua scripting engine. +-} +module PandocCLI.Lua (runLuaInterpreter, getEngine) where + +import Control.Monad ((<=<)) +import HsLua.CLI (EnvBehavior (..), Settings (..), runStandalone) +import Text.Pandoc.Class (runIOorExplode) +import Text.Pandoc.Error (handleError) +import Text.Pandoc.Lua (runLua, runLuaNoEnv, getEngine) +import Text.Pandoc.Shared (pandocVersionText) + +-- | Runs pandoc as a Lua interpreter that is (mostly) compatible with +-- the default @lua@ program shipping with Lua. +runLuaInterpreter :: String -- ^ Program name + -> [String] -- ^ Command line arguments + -> IO () +runLuaInterpreter progName args = do + let settings = Settings + { settingsVersionInfo = "\nEmbedded in pandoc " <> pandocVersionText + , settingsRunner = runner + } + runStandalone settings progName args + where + runner envBehavior = + let runLua' = case envBehavior of + IgnoreEnvVars -> runLuaNoEnv + ConsultEnvVars -> runLua + in handleError <=< runIOorExplode . runLua' |
