diff options
| -rw-r--r-- | MANUAL.txt | 3 | ||||
| -rw-r--r-- | pandoc-cli/src/pandoc.hs | 10 | ||||
| -rw-r--r-- | src/Text/Pandoc/Lua.hs | 3 | ||||
| -rw-r--r-- | src/Text/Pandoc/Lua/Init.hs | 14 |
4 files changed, 24 insertions, 6 deletions
diff --git a/MANUAL.txt b/MANUAL.txt index e99c84ef5..44881895c 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -7102,8 +7102,7 @@ Calling the pandoc executable under the name `pandoc-lua` or with `lua` as the first argument will make it function as a standalone Lua interpreter. The behavior is mostly identical to that of the [standalone `lua` executable][lua standalone], version 5.4. -However, there is no REPL yet, and the options `-W`, `-E`, and -`-i` currently don't have any effect. +However, there is no REPL yet, and the `-i` option has no effect. [lua standalone]: https://www.lua.org/manual/5.4/manual.html#7 diff --git a/pandoc-cli/src/pandoc.hs b/pandoc-cli/src/pandoc.hs index 630352c2c..47a8988f0 100644 --- a/pandoc-cli/src/pandoc.hs +++ b/pandoc-cli/src/pandoc.hs @@ -14,13 +14,13 @@ writers. module Main where import Control.Monad ((<=<)) import qualified Control.Exception as E -import HsLua.CLI (Settings (..), runStandalone) +import HsLua.CLI (EnvBehavior (..), Settings (..), runStandalone) import System.Environment (getArgs, getProgName) import Text.Pandoc.App ( convertWithOpts, defaultOpts, options , parseOptionsFromArgs) import Text.Pandoc.Class (runIOorExplode) import Text.Pandoc.Error (handleError) -import Text.Pandoc.Lua (runLua) +import Text.Pandoc.Lua (runLua, runLuaNoEnv) import Text.Pandoc.Shared (pandocVersion) import qualified Text.Pandoc.UTF8 as UTF8 import PandocCLI.Server @@ -50,4 +50,8 @@ runLuaInterpreter progName args = do } runStandalone settings progName args where - runner _envBehavior = handleError <=< runIOorExplode . runLua + runner envBehavior = + let runLua' = case envBehavior of + IgnoreEnvVars -> runLuaNoEnv + ConsultEnvVars -> runLua + in handleError <=< runIOorExplode . runLua' diff --git a/src/Text/Pandoc/Lua.hs b/src/Text/Pandoc/Lua.hs index 28e807ae9..085526cb7 100644 --- a/src/Text/Pandoc/Lua.hs +++ b/src/Text/Pandoc/Lua.hs @@ -20,11 +20,12 @@ module Text.Pandoc.Lua , Global(..) , setGlobals , runLua + , runLuaNoEnv ) where import Text.Pandoc.Lua.Filter (applyFilter) import Text.Pandoc.Lua.Global (Global (..), setGlobals) -import Text.Pandoc.Lua.Init (runLua) +import Text.Pandoc.Lua.Init (runLua, runLuaNoEnv) import Text.Pandoc.Lua.Reader (readCustom) import Text.Pandoc.Lua.Writer (writeCustom) import Text.Pandoc.Lua.Orphans () diff --git a/src/Text/Pandoc/Lua/Init.hs b/src/Text/Pandoc/Lua/Init.hs index 966f0a581..04f007e0e 100644 --- a/src/Text/Pandoc/Lua/Init.hs +++ b/src/Text/Pandoc/Lua/Init.hs @@ -12,6 +12,7 @@ Functions to initialize the Lua interpreter. -} module Text.Pandoc.Lua.Init ( runLua + , runLuaNoEnv ) where import Control.Monad (forM, forM_, when) @@ -46,6 +47,19 @@ runLua action = initLuaState liftPandocLua action +-- | Like 'runLua', but ignores all environment variables like @LUA_PATH@. +runLuaNoEnv :: (PandocMonad m, MonadIO m) + => LuaE PandocError a -> m (Either PandocError a) +runLuaNoEnv action = + runPandocLua . try $ do + liftPandocLua $ do + -- This is undocumented, but works -- the code is adapted from the + -- `lua.c` sources for the default interpreter. + Lua.pushboolean True + Lua.setfield Lua.registryindex "LUA_NOENV" + initLuaState + liftPandocLua action + -- | Modules that are loaded at startup and assigned to fields in the -- pandoc module. -- |
