summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua/Init.hs
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2022-09-27 13:09:55 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2022-09-27 08:42:27 -0700
commitefecff1f2f035ee3a0825e969d048d6c5ffacd26 (patch)
treee73fa73d741472d1dc2ac00d77e76d6591c6e9a8 /src/Text/Pandoc/Lua/Init.hs
parent175b791529a960bf7df8bccb8876783076b3d321 (diff)
pandoc-cli: support `-E` flag in pandoc-lua
Diffstat (limited to 'src/Text/Pandoc/Lua/Init.hs')
-rw-r--r--src/Text/Pandoc/Lua/Init.hs14
1 files changed, 14 insertions, 0 deletions
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.
--