From efecff1f2f035ee3a0825e969d048d6c5ffacd26 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 27 Sep 2022 13:09:55 +0200 Subject: pandoc-cli: support `-E` flag in pandoc-lua --- src/Text/Pandoc/Lua.hs | 3 ++- src/Text/Pandoc/Lua/Init.hs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src') 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. -- -- cgit v1.2.3