diff options
| author | Albert Krewinkel <[email protected]> | 2022-09-29 17:59:31 +0200 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-09-30 08:33:40 -0700 |
| commit | b6a571d5774176202c1719f626c497f1bcdbaf2c (patch) | |
| tree | 2eb50335ee48bdf22286cc898403ccc1d9be979b /pandoc-cli/lua | |
| parent | 5be9052f5fb7283372b3d5497bef499718a34992 (diff) | |
pandoc-cli: Allow building a binary without Lua support
Disabling the `lua` cabal flag will result in a binary without Lua.
Diffstat (limited to 'pandoc-cli/lua')
| -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 <[email protected]> + +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' |
