git.iko.soy/typeable/pandoc
on master help sign in
Lua: fix regression in package searcher

This caused `require 'module'` to fail for third party packages. Fixes: #6361

commit9c76c52e9bb1481234b8ee5ef9c524a5a61d43bd authorAlbert Krewinkel <albert@zeitkraut.de> dateTue 12 May 2020, 17:10 (6 years ago) parent82eb4df
3 files changed+16−2
src/Text/Pandoc/Lua/Packages.hs+8−2 test/Tests/Lua.hs+6 test/lua/require-file.lua+2
src/Text/Pandoc/Lua/Packages.hs+8−2
@@ -1,4 +1,5 @@
11{-# LANGUAGE FlexibleContexts #-}
2+{-# LANGUAGE LambdaCase #-}
23{-# LANGUAGE ScopedTypeVariables #-}
34{- |
45 Module : Text.Pandoc.Lua.Packages
@@ -14,9 +15,11 @@ module Text.Pandoc.Lua.Packages
1415 ( installPandocPackageSearcher
1516 ) where
1617
18+import Control.Monad.Catch (try)
1719import Control.Monad (forM_)
1820import Data.ByteString (ByteString)
1921import Foreign.Lua (Lua, NumResults)
22+import Text.Pandoc.Error (PandocError)
2023import Text.Pandoc.Class.PandocMonad (readDataFile)
2124import Text.Pandoc.Lua.PandocLua (PandocLua, liftPandocLua)
2225
@@ -58,8 +61,11 @@ pandocPackageSearcher pkgName =
5861 return 1
5962 searchPureLuaLoader = do
6063 let filename = pkgName ++ ".lua"
61− script <- readDataFile filename
62− pushWrappedHsFun (loadStringAsPackage pkgName script)
64+ try (readDataFile filename) >>= \case
65+ Right script -> pushWrappedHsFun (loadStringAsPackage pkgName script)
66+ Left (_ :: PandocError) -> liftPandocLua $ do
67+ Lua.push ("\n\tno file '" ++ filename ++ "' in pandoc's datadir")
68+ return (1 :: NumResults)
6369
6470loadStringAsPackage :: String -> ByteString -> Lua NumResults
6571loadStringAsPackage pkgName script = do
test/Tests/Lua.hs+6
@@ -172,6 +172,12 @@ tests = map (localOption (QuickCheckTests 20))
172172 Lua.liftIO . assertEqual "pandoc-types version is wrong" pandocTypesVersion
173173 =<< Lua.peek Lua.stackTop
174174
175+ , testCase "require file" $
176+ assertFilterConversion "requiring file failed"
177+ "require-file.lua"
178+ (doc $ para "ignored")
179+ (doc $ para (str . T.pack $ "lua" </> "require-file.lua"))
180+
175181 , testCase "Allow singleton inline in constructors" . runLuaTest $ do
176182 Lua.liftIO . assertEqual "Not the exptected Emph" (Emph [Str "test"])
177183 =<< Lua.callFunc "pandoc.Emph" (Str "test")
test/lua/require-file.luanew file+2
@@ -0,0 +1,2 @@
1+package.path = package.path .. ';lua/?.lua'
2+require 'script-name'