summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua.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.hs
parent39dd7c794bc881acd2030c07ddfb7b34842f19a3 (diff)
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.hs')
-rw-r--r--src/Text/Pandoc/Lua.hs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Lua.hs b/src/Text/Pandoc/Lua.hs
index 790be47d5..79955509d 100644
--- a/src/Text/Pandoc/Lua.hs
+++ b/src/Text/Pandoc/Lua.hs
@@ -37,7 +37,7 @@ import Foreign.Lua (FromLuaStack (peek), Lua, LuaException (..),
import Text.Pandoc.Class (PandocIO)
import Text.Pandoc.Definition (Pandoc)
import Text.Pandoc.Lua.Filter (LuaFilter, walkMWithLuaFilter)
-import Text.Pandoc.Lua.Init (runPandocLua)
+import Text.Pandoc.Lua.Init (runPandocLua, registerScriptPath)
import Text.Pandoc.Lua.Util (popValue)
import Text.Pandoc.Options (ReaderOptions)
import qualified Foreign.Lua as Lua
@@ -55,11 +55,12 @@ runLuaFilter' :: ReaderOptions -> FilePath -> String
runLuaFilter' ropts filterPath format pd = do
registerFormat
registerReaderOptions
+ registerScriptPath filterPath
top <- Lua.gettop
stat <- Lua.dofile filterPath
if stat /= OK
then do
- luaErrMsg <- peek (-1) <* Lua.pop 1
+ luaErrMsg <- popValue
Lua.throwLuaError luaErrMsg
else do
newtop <- Lua.gettop