git.iko.soy/typeable/pandoc
on master help sign in
T.P.Lua: rename `runPandocLua` to `runLua` (API change)
6f29e1cAlbert Krewinkel
src/Text/Pandoc/Filter/Lua.hs+2−2
@@ -38,7 +38,7 @@ import Text.Pandoc.Class (PandocIO)
38import Text.Pandoc.Definition (Pandoc)
38import Text.Pandoc.Definition (Pandoc)
39import Text.Pandoc.Error (PandocError (PandocFilterError))
39import Text.Pandoc.Error (PandocError (PandocFilterError))
40import Text.Pandoc.Filter.Path (expandFilterPath)
40import Text.Pandoc.Filter.Path (expandFilterPath)
41−import Text.Pandoc.Lua (LuaException (..), runPandocLua)
41+import Text.Pandoc.Lua (LuaException (..), runLua)
42import Text.Pandoc.Lua.Filter (LuaFilter, walkMWithLuaFilter)
42import Text.Pandoc.Lua.Filter (LuaFilter, walkMWithLuaFilter)
43import Text.Pandoc.Lua.Global (Global (..), setGlobals)
43import Text.Pandoc.Lua.Global (Global (..), setGlobals)
44import Text.Pandoc.Lua.Util (dofileWithTraceback)
44import Text.Pandoc.Lua.Util (dofileWithTraceback)
@@ -59,7 +59,7 @@ apply ropts args f doc = do
59 let format = case args of
59 let format = case args of
60 (x:_) -> x
60 (x:_) -> x
61 _ -> error "Format not supplied for Lua filter"
61 _ -> error "Format not supplied for Lua filter"
62− runPandocLua >=> forceResult filterPath $ do
62+ runLua >=> forceResult filterPath $ do
63 setGlobals [ FORMAT format
63 setGlobals [ FORMAT format
64 , PANDOC_READER_OPTIONS ropts
64 , PANDOC_READER_OPTIONS ropts
65 , PANDOC_SCRIPT_FILE filterPath
65 , PANDOC_SCRIPT_FILE filterPath
src/Text/Pandoc/Lua.hs+2−2
@@ -28,8 +28,8 @@ Running pandoc Lua filters.
28-}
28-}
29module Text.Pandoc.Lua
29module Text.Pandoc.Lua
30 ( LuaException (..)
30 ( LuaException (..)
31− , runPandocLua
31+ , runLua
32 ) where
32 ) where
33
33
34−import Text.Pandoc.Lua.Init (LuaException (..), runPandocLua)
34+import Text.Pandoc.Lua.Init (LuaException (..), runLua)
35
35
src/Text/Pandoc/Lua/Init.hs+3−3
@@ -29,7 +29,7 @@ Functions to initialize the Lua interpreter.
29module Text.Pandoc.Lua.Init
29module Text.Pandoc.Lua.Init
30 ( LuaException (..)
30 ( LuaException (..)
31 , LuaPackageParams (..)
31 , LuaPackageParams (..)
32− , runPandocLua
32+ , runLua
33 , initLuaState
33 , initLuaState
34 , luaPackageParams
34 , luaPackageParams
35 ) where
35 ) where
@@ -56,8 +56,8 @@ newtype LuaException = LuaException String deriving (Show)
56
56
57-- | Run the lua interpreter, using pandoc's default way of environment
57-- | Run the lua interpreter, using pandoc's default way of environment
58-- initialization.
58-- initialization.
59−runPandocLua :: Lua a -> PandocIO (Either LuaException a)
59+runLua :: Lua a -> PandocIO (Either LuaException a)
60−runPandocLua luaOp = do
60+runLua luaOp = do
61 luaPkgParams <- luaPackageParams
61 luaPkgParams <- luaPackageParams
62 globals <- defaultGlobals
62 globals <- defaultGlobals
63 enc <- liftIO $ getForeignEncoding <* setForeignEncoding utf8
63 enc <- liftIO $ getForeignEncoding <* setForeignEncoding utf8
src/Text/Pandoc/Writers/Custom.hs+2−2
@@ -44,7 +44,7 @@ import Text.Pandoc.Class (PandocIO)
44import Text.Pandoc.Definition
44import Text.Pandoc.Definition
45import Text.Pandoc.Error
45import Text.Pandoc.Error
46import Text.Pandoc.Lua.Global (Global (..), setGlobals)
46import Text.Pandoc.Lua.Global (Global (..), setGlobals)
47−import Text.Pandoc.Lua.Init (LuaException (LuaException), runPandocLua)
47+import Text.Pandoc.Lua.Init (LuaException (LuaException), runLua)
48import Text.Pandoc.Lua.StackInstances ()
48import Text.Pandoc.Lua.StackInstances ()
49import Text.Pandoc.Lua.Util (addField, dofileWithTraceback)
49import Text.Pandoc.Lua.Util (addField, dofileWithTraceback)
50import Text.Pandoc.Options
50import Text.Pandoc.Options
@@ -111,7 +111,7 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
111 let globals = [ PANDOC_DOCUMENT doc
111 let globals = [ PANDOC_DOCUMENT doc
112 , PANDOC_SCRIPT_FILE luaFile
112 , PANDOC_SCRIPT_FILE luaFile
113 ]
113 ]
114− res <- runPandocLua $ do
114+ res <- runLua $ do
115 setGlobals globals
115 setGlobals globals
116 stat <- dofileWithTraceback luaFile
116 stat <- dofileWithTraceback luaFile
117 -- check for error in lua script (later we'll change the return type
117 -- check for error in lua script (later we'll change the return type
test/Tests/Lua.hs+10−10
@@ -18,7 +18,7 @@ import Text.Pandoc.Class (runIOorExplode, setUserDataDir)
18import Text.Pandoc.Definition (Block (BlockQuote, Div, Para), Inline (Emph, Str),
18import Text.Pandoc.Definition (Block (BlockQuote, Div, Para), Inline (Emph, Str),
19 Attr, Meta, Pandoc, pandocTypesVersion)
19 Attr, Meta, Pandoc, pandocTypesVersion)
20import Text.Pandoc.Filter (Filter (LuaFilter), applyFilters)
20import Text.Pandoc.Filter (Filter (LuaFilter), applyFilters)
21−import Text.Pandoc.Lua (runPandocLua)
21+import Text.Pandoc.Lua (runLua)
22import Text.Pandoc.Options (def)
22import Text.Pandoc.Options (def)
23import Text.Pandoc.Shared (pandocVersion)
23import Text.Pandoc.Shared (pandocVersion)
24
24
@@ -128,7 +128,7 @@ tests = map (localOption (QuickCheckTests 20))
128 (doc $ para "ignored")
128 (doc $ para "ignored")
129 (doc $ para (str $ "lua" </> "script-name.lua"))
129 (doc $ para (str $ "lua" </> "script-name.lua"))
130
130
131− , testCase "Pandoc version is set" . runPandocLua' $ do
131+ , testCase "Pandoc version is set" . runLua' $ do
132 Lua.getglobal' "table.concat"
132 Lua.getglobal' "table.concat"
133 Lua.getglobal "PANDOC_VERSION"
133 Lua.getglobal "PANDOC_VERSION"
134 Lua.push ("." :: String) -- separator
134 Lua.push ("." :: String) -- separator
@@ -136,13 +136,13 @@ tests = map (localOption (QuickCheckTests 20))
136 Lua.liftIO . assertEqual "pandoc version is wrong" pandocVersion
136 Lua.liftIO . assertEqual "pandoc version is wrong" pandocVersion
137 =<< Lua.peek Lua.stackTop
137 =<< Lua.peek Lua.stackTop
138
138
139− , testCase "Pandoc types version is set" . runPandocLua' $ do
139+ , testCase "Pandoc types version is set" . runLua' $ do
140 let versionNums = versionBranch pandocTypesVersion
140 let versionNums = versionBranch pandocTypesVersion
141 Lua.getglobal "PANDOC_API_VERSION"
141 Lua.getglobal "PANDOC_API_VERSION"
142 Lua.liftIO . assertEqual "pandoc-types version is wrong" versionNums
142 Lua.liftIO . assertEqual "pandoc-types version is wrong" versionNums
143 =<< Lua.peek Lua.stackTop
143 =<< Lua.peek Lua.stackTop
144
144
145− , testCase "Allow singleton inline in constructors" . runPandocLua' $ do
145+ , testCase "Allow singleton inline in constructors" . runLua' $ do
146 Lua.liftIO . assertEqual "Not the exptected Emph" (Emph [Str "test"])
146 Lua.liftIO . assertEqual "Not the exptected Emph" (Emph [Str "test"])
147 =<< Lua.callFunc "pandoc.Emph" (Str "test")
147 =<< Lua.callFunc "pandoc.Emph" (Str "test")
148 Lua.liftIO . assertEqual "Unexpected element" (Para [Str "test"])
148 Lua.liftIO . assertEqual "Unexpected element" (Para [Str "test"])
@@ -156,14 +156,14 @@ tests = map (localOption (QuickCheckTests 20))
156 Lua.peek Lua.stackTop
156 Lua.peek Lua.stackTop
157 )
157 )
158
158
159− , testCase "Elements with Attr have `attr` accessor" . runPandocLua' $ do
159+ , testCase "Elements with Attr have `attr` accessor" . runLua' $ do
160 Lua.push (Div ("hi", ["moin"], [])
160 Lua.push (Div ("hi", ["moin"], [])
161 [Para [Str "ignored"]])
161 [Para [Str "ignored"]])
162 Lua.getfield Lua.stackTop "attr"
162 Lua.getfield Lua.stackTop "attr"
163 Lua.liftIO . assertEqual "no accessor" (("hi", ["moin"], []) :: Attr)
163 Lua.liftIO . assertEqual "no accessor" (("hi", ["moin"], []) :: Attr)
164 =<< Lua.peek Lua.stackTop
164 =<< Lua.peek Lua.stackTop
165
165
166− , testCase "informative error messages" . runPandocLua' $ do
166+ , testCase "informative error messages" . runLua' $ do
167 Lua.pushboolean True
167 Lua.pushboolean True
168 err <- Lua.peekEither Lua.stackTop
168 err <- Lua.peekEither Lua.stackTop
169 case (err :: Either String Pandoc) of
169 case (err :: Either String Pandoc) of
@@ -185,7 +185,7 @@ roundtripEqual :: (Eq a, Lua.Peekable a, Lua.Pushable a) => a -> IO Bool
185roundtripEqual x = (x ==) <$> roundtripped
185roundtripEqual x = (x ==) <$> roundtripped
186 where
186 where
187 roundtripped :: (Lua.Peekable a, Lua.Pushable a) => IO a
187 roundtripped :: (Lua.Peekable a, Lua.Pushable a) => IO a
188− roundtripped = runPandocLua' $ do
188+ roundtripped = runLua' $ do
189 oldSize <- Lua.gettop
189 oldSize <- Lua.gettop
190 Lua.push x
190 Lua.push x
191 size <- Lua.gettop
191 size <- Lua.gettop
@@ -196,10 +196,10 @@ roundtripEqual x = (x ==) <$> roundtripped
196 Left e -> error (show e)
196 Left e -> error (show e)
197 Right y -> return y
197 Right y -> return y
198
198
199−runPandocLua' :: Lua.Lua a -> IO a
199+runLua' :: Lua.Lua a -> IO a
200−runPandocLua' op = runIOorExplode $ do
200+runLua' op = runIOorExplode $ do
201 setUserDataDir (Just "../data")
201 setUserDataDir (Just "../data")
202− res <- runPandocLua op
202+ res <- runLua op
203 case res of
203 case res of
204 Left e -> error (show e)
204 Left e -> error (show e)
205 Right x -> return x
205 Right x -> return x