aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua/Init.hs
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2018-02-24 21:59:50 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2018-02-24 22:43:28 +0100
commitb5bd8a9461dc317ff61abec68feba4a86d39e9f2 (patch)
treea22e940d299d0fb8741d7347ea4be69b3c6c48e9 /src/Text/Pandoc/Lua/Init.hs
parent39dd7c794bc881acd2030c07ddfb7b34842f19a3 (diff)
downloadpandoc-b5bd8a9461dc317ff61abec68feba4a86d39e9f2.tar.gz
Lua: register script name in global variable
The name of the Lua script which is executed is made available in the global Lua variable `PANDOC_SCRIPT_FILE`, both for Lua filters and custom writers. Closes: #4393
Diffstat (limited to 'src/Text/Pandoc/Lua/Init.hs')
-rw-r--r--src/Text/Pandoc/Lua/Init.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Lua/Init.hs b/src/Text/Pandoc/Lua/Init.hs
index d1a26ebad..8fa228837 100644
--- a/src/Text/Pandoc/Lua/Init.hs
+++ b/src/Text/Pandoc/Lua/Init.hs
@@ -31,6 +31,7 @@ module Text.Pandoc.Lua.Init
, runPandocLua
, initLuaState
, luaPackageParams
+ , registerScriptPath
) where
import Control.Monad.Trans (MonadIO (..))
@@ -88,6 +89,11 @@ initLuaState luaPkgParams = do
loadScriptFromDataDir (luaPkgDataDir luaPkgParams) "init.lua"
putConstructorsInRegistry
+registerScriptPath :: FilePath -> Lua ()
+registerScriptPath fp = do
+ Lua.push fp
+ Lua.setglobal "PANDOC_SCRIPT_FILE"
+
putConstructorsInRegistry :: Lua ()
putConstructorsInRegistry = do
Lua.getglobal "pandoc"
@@ -101,7 +107,7 @@ putConstructorsInRegistry = do
Lua.pop 1
where
constrsToReg :: Data a => a -> Lua ()
- constrsToReg = mapM_ putInReg . map showConstr . dataTypeConstrs . dataTypeOf
+ constrsToReg = mapM_ (putInReg . showConstr) . dataTypeConstrs . dataTypeOf
putInReg :: String -> Lua ()
putInReg name = do