aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2021-11-08 12:14:44 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2021-11-08 12:22:33 +0100
commitab0fe676a8507ea1ff4e77b97f548a92b13b6317 (patch)
tree7b181b9b1d433b0dc163254436c8652907b41ed0 /src/Text
parentcc46667953b609d87bbf5611f50843871b304a0c (diff)
downloadpandoc-ab0fe676a8507ea1ff4e77b97f548a92b13b6317.tar.gz
Lua: ensure that 're' module is always available.
The module is shipped with LPeg.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Lua/Init.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Lua/Init.hs b/src/Text/Pandoc/Lua/Init.hs
index 5b2a2f3e4..727c79d84 100644
--- a/src/Text/Pandoc/Lua/Init.hs
+++ b/src/Text/Pandoc/Lua/Init.hs
@@ -46,6 +46,7 @@ initLuaState :: PandocLua ()
initLuaState = do
liftPandocLua Lua.openlibs
installPandocPackageSearcher
+ installLpegSearcher
initPandocModule
requireGlobalModules
loadInitScript "init.lua"
@@ -99,6 +100,13 @@ initLuaState = do
-- Module on top of stack. Register as global
Lua.setglobal "lpeg"
+ installLpegSearcher :: PandocLua ()
+ installLpegSearcher = liftPandocLua $ do
+ Lua.getglobal' "package.searchers"
+ Lua.pushHaskellFunction $ Lua.state >>= liftIO . LPeg.lpeg_searcher
+ Lua.rawseti (Lua.nth 2) . (+1) . fromIntegral =<< Lua.rawlen (Lua.nth 2)
+ Lua.pop 1 -- remove 'package.searchers' from stack
+
-- | AST elements are marshaled via normal constructor functions in the
-- @pandoc@ module. However, accessing Lua globals from Haskell is
-- expensive (due to error handling). Accessing the Lua registry is much