git.iko.soy/typeable/pandoc
on master help sign in
T.P.Lua: split StackInstances into smaller Marshaling modules
331d622Albert Krewinkel
pandoc.cabal+5−1
@@ -575,11 +575,15 @@ library
575 Text.Pandoc.Lua.Filter,
575 Text.Pandoc.Lua.Filter,
576 Text.Pandoc.Lua.Global,
576 Text.Pandoc.Lua.Global,
577 Text.Pandoc.Lua.Init,
577 Text.Pandoc.Lua.Init,
578+ Text.Pandoc.Lua.Marshaling,
579+ Text.Pandoc.Lua.Marshaling.AST,
580+ Text.Pandoc.Lua.Marshaling.AnyValue,
581+ Text.Pandoc.Lua.Marshaling.CommonState,
582+ Text.Pandoc.Lua.Marshaling.ReaderOptions,
578 Text.Pandoc.Lua.Module.MediaBag,
583 Text.Pandoc.Lua.Module.MediaBag,
579 Text.Pandoc.Lua.Module.Pandoc,
584 Text.Pandoc.Lua.Module.Pandoc,
580 Text.Pandoc.Lua.Module.Utils,
585 Text.Pandoc.Lua.Module.Utils,
581 Text.Pandoc.Lua.Packages,
586 Text.Pandoc.Lua.Packages,
582− Text.Pandoc.Lua.StackInstances,
583 Text.Pandoc.Lua.Util,
587 Text.Pandoc.Lua.Util,
584 Text.Pandoc.CSS,
588 Text.Pandoc.CSS,
585 Text.Pandoc.CSV,
589 Text.Pandoc.CSV,
src/Text/Pandoc/Lua.hs+1−1
@@ -39,5 +39,5 @@ module Text.Pandoc.Lua
39import Text.Pandoc.Lua.Filter (runFilterFile)
39import Text.Pandoc.Lua.Filter (runFilterFile)
40import Text.Pandoc.Lua.Global (Global (..), setGlobals)
40import Text.Pandoc.Lua.Global (Global (..), setGlobals)
41import Text.Pandoc.Lua.Init (LuaException (..), runLua)
41import Text.Pandoc.Lua.Init (LuaException (..), runLua)
42−import Text.Pandoc.Lua.StackInstances ()
42+import Text.Pandoc.Lua.Marshaling ()
43
43
src/Text/Pandoc/Lua/Filter.hs+1−1
@@ -48,7 +48,7 @@ import Data.Foldable (foldrM)
48import Data.Map (Map)
48import Data.Map (Map)
49import Foreign.Lua (Lua, Peekable, Pushable)
49import Foreign.Lua (Lua, Peekable, Pushable)
50import Text.Pandoc.Definition
50import Text.Pandoc.Definition
51−import Text.Pandoc.Lua.StackInstances ()
51+import Text.Pandoc.Lua.Marshaling ()
52import Text.Pandoc.Walk (walkM, Walkable)
52import Text.Pandoc.Walk (walkM, Walkable)
53
53
54import qualified Data.Map.Strict as Map
54import qualified Data.Map.Strict as Map
src/Text/Pandoc/Lua/Global.hs+1−1
@@ -41,7 +41,7 @@ import Foreign.Lua.Userdata ( ensureUserdataMetatable, pushAnyWithMetatable
41import Paths_pandoc (version)
41import Paths_pandoc (version)
42import Text.Pandoc.Class (CommonState)
42import Text.Pandoc.Class (CommonState)
43import Text.Pandoc.Definition (Pandoc (Pandoc), pandocTypesVersion)
43import Text.Pandoc.Definition (Pandoc (Pandoc), pandocTypesVersion)
44−import Text.Pandoc.Lua.StackInstances ()
44+import Text.Pandoc.Lua.Marshaling ()
45import Text.Pandoc.Lua.Util (addFunction)
45import Text.Pandoc.Lua.Util (addFunction)
46import Text.Pandoc.Options (ReaderOptions)
46import Text.Pandoc.Options (ReaderOptions)
47
47
src/Text/Pandoc/Lua/Marshaling.hsnew file+16
@@ -0,0 +1,16 @@
1+{- |
2+ Module : Text.Pandoc.Lua.Marshaling
3+ Copyright : © 2012-2019 John MacFarlane
4+ © 2017-2019 Albert Krewinkel
5+ License : GNU GPL, version 2 or above
6+
7+ Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
8+ Stability : alpha
9+
10+Lua marshaling (pushing) and unmarshaling (peeking) instances.
11+-}
12+module Text.Pandoc.Lua.Marshaling () where
13+
14+import Text.Pandoc.Lua.Marshaling.AST ()
15+import Text.Pandoc.Lua.Marshaling.CommonState ()
16+import Text.Pandoc.Lua.Marshaling.ReaderOptions ()
src/Text/Pandoc/Lua/StackInstances.hs → src/Text/Pandoc/Lua/Marshaling/AST.hsrenamed+6−168
@@ -1,28 +1,10 @@
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE LambdaCase #-}
5{-# LANGUAGE LambdaCase #-}
5−{-# OPTIONS_GHC -fno-warn-orphans #-}
6−{-
7−Copyright © 2012-2019 John MacFarlane <jgm@berkeley.edu>
8− 2017-2019 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
9−
10−This program is free software; you can redistribute it and/or modify
11−it under the terms of the GNU General Public License as published by
12−the Free Software Foundation; either version 2 of the License, or
13−(at your option) any later version.
14−
15−This program is distributed in the hope that it will be useful,
16−but WITHOUT ANY WARRANTY; without even the implied warranty of
17−MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18−GNU General Public License for more details.
19−
20−You should have received a copy of the GNU General Public License
21−along with this program; if not, write to the Free Software
22−Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23−-}
24{- |
6{- |
25− Module : Text.Pandoc.Lua.StackInstances
7+ Module : Text.Pandoc.Lua.Marshaling.AST
26 Copyright : © 2012-2019 John MacFarlane
8 Copyright : © 2012-2019 John MacFarlane
27 © 2017-2019 Albert Krewinkel
9 © 2017-2019 Albert Krewinkel
28 License : GNU GPL, version 2 or above
10 License : GNU GPL, version 2 or above
@@ -30,27 +12,20 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
12 Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
31 Stability : alpha
13 Stability : alpha
32
14
33−StackValue instances for pandoc types.
15+Marshaling/unmarshaling instances for document AST elements.
34-}
16-}
35−module Text.Pandoc.Lua.StackInstances () where
17+module Text.Pandoc.Lua.Marshaling.AST () where
36
18
37import Prelude
19import Prelude
38import Control.Applicative ((<|>))
20import Control.Applicative ((<|>))
39−import Data.Data (showConstr, toConstr)
40import Foreign.Lua (Lua, Peekable, Pushable, StackIndex)
21import Foreign.Lua (Lua, Peekable, Pushable, StackIndex)
41−import Foreign.Lua.Types.Peekable (reportValueOnFailure)
42import Foreign.Lua.Userdata ( ensureUserdataMetatable, pushAnyWithMetatable
22import Foreign.Lua.Userdata ( ensureUserdataMetatable, pushAnyWithMetatable
43− , toAnyWithName, metatableName)
23+ , metatableName)
44−import Text.Pandoc.Class (CommonState (..))
45import Text.Pandoc.Definition
24import Text.Pandoc.Definition
46−import Text.Pandoc.Extensions (Extensions)
47−import Text.Pandoc.Logging (LogMessage, showLogMessage)
48import Text.Pandoc.Lua.Util (defineHowTo, pushViaConstructor)
25import Text.Pandoc.Lua.Util (defineHowTo, pushViaConstructor)
49−import Text.Pandoc.Options (ReaderOptions (..), TrackChanges)
26+import Text.Pandoc.Lua.Marshaling.CommonState ()
50import Text.Pandoc.Shared (Element (Blk, Sec))
27import Text.Pandoc.Shared (Element (Blk, Sec))
51
28
52−import qualified Data.Map as Map
53−import qualified Data.Set as Set
54import qualified Foreign.Lua as Lua
29import qualified Foreign.Lua as Lua
55import qualified Text.Pandoc.Lua.Util as LuaUtil
30import qualified Text.Pandoc.Lua.Util as LuaUtil
56
31
@@ -335,140 +310,3 @@ indexElement = \case
335 "tag" -> Lua.push "Sec"
310 "tag" -> Lua.push "Sec"
336 "t" -> Lua.push "Sec"
311 "t" -> Lua.push "Sec"
337 _ -> Lua.pushnil
312 _ -> Lua.pushnil
338−
339−
340−--
341−-- Reader Options
342−--
343−instance Pushable Extensions where
344− push exts = Lua.push (show exts)
345−
346−instance Pushable TrackChanges where
347− push = Lua.push . showConstr . toConstr
348−
349−instance Pushable ReaderOptions where
350− push ro = do
351− let ReaderOptions
352− (extensions :: Extensions)
353− (standalone :: Bool)
354− (columns :: Int)
355− (tabStop :: Int)
356− (indentedCodeClasses :: [String])
357− (abbreviations :: Set.Set String)
358− (defaultImageExtension :: String)
359− (trackChanges :: TrackChanges)
360− (stripComments :: Bool)
361− = ro
362− Lua.newtable
363− LuaUtil.addField "extensions" extensions
364− LuaUtil.addField "standalone" standalone
365− LuaUtil.addField "columns" columns
366− LuaUtil.addField "tab_stop" tabStop
367− LuaUtil.addField "indented_code_classes" indentedCodeClasses
368− LuaUtil.addField "abbreviations" abbreviations
369− LuaUtil.addField "default_image_extension" defaultImageExtension
370− LuaUtil.addField "track_changes" trackChanges
371− LuaUtil.addField "strip_comments" stripComments
372−
373− -- add metatable
374− let indexReaderOptions :: AnyValue -> AnyValue -> Lua Lua.NumResults
375− indexReaderOptions _tbl (AnyValue key) = do
376− Lua.ltype key >>= \case
377− Lua.TypeString -> Lua.peek key >>= \case
378− "defaultImageExtension" -> Lua.push defaultImageExtension
379− "indentedCodeClasses" -> Lua.push indentedCodeClasses
380− "stripComments" -> Lua.push stripComments
381− "tabStop" -> Lua.push tabStop
382− "trackChanges" -> Lua.push trackChanges
383− _ -> Lua.pushnil
384− _ -> Lua.pushnil
385− return 1
386− Lua.newtable
387− LuaUtil.addFunction "__index" indexReaderOptions
388− Lua.setmetatable (Lua.nthFromTop 2)
389−
390−-- | Dummy type to allow values of arbitrary Lua type.
391−newtype AnyValue = AnyValue StackIndex
392−
393−--
394−-- TODO: Much of the following should be abstracted, factored out
395−-- and go into HsLua.
396−--
397−
398−instance Peekable AnyValue where
399− peek = return . AnyValue
400−
401−-- | Name used by Lua for the @CommonState@ type.
402−commonStateTypeName :: String
403−commonStateTypeName = "Pandoc CommonState"
404−
405−instance Peekable CommonState where
406− peek idx = reportValueOnFailure commonStateTypeName
407− (`toAnyWithName` commonStateTypeName) idx
408−
409−instance Pushable CommonState where
410− push st = pushAnyWithMetatable pushCommonStateMetatable st
411− where
412− pushCommonStateMetatable = ensureUserdataMetatable commonStateTypeName $ do
413− LuaUtil.addFunction "__index" indexCommonState
414− LuaUtil.addFunction "__pairs" pairsCommonState
415−
416−indexCommonState :: CommonState -> AnyValue -> Lua Lua.NumResults
417−indexCommonState st (AnyValue idx) = Lua.ltype idx >>= \case
418− Lua.TypeString -> 1 <$ (Lua.peek idx >>= pushField)
419− _ -> 1 <$ Lua.pushnil
420− where
421− pushField :: String -> Lua ()
422− pushField name = case lookup name commonStateFields of
423− Just pushValue -> pushValue st
424− Nothing -> Lua.pushnil
425−
426−pairsCommonState :: CommonState -> Lua Lua.NumResults
427−pairsCommonState st = do
428− Lua.pushHaskellFunction nextFn
429− Lua.pushnil
430− Lua.pushnil
431− return 3
432− where
433− nextFn :: AnyValue -> AnyValue -> Lua Lua.NumResults
434− nextFn _ (AnyValue idx) =
435− Lua.ltype idx >>= \case
436− Lua.TypeNil -> case commonStateFields of
437− [] -> 2 <$ (Lua.pushnil *> Lua.pushnil)
438− (key, pushValue):_ -> 2 <$ (Lua.push key *> pushValue st)
439− Lua.TypeString -> do
440− key <- Lua.peek idx
441− case tail $ dropWhile ((/= key) . fst) commonStateFields of
442− [] -> 2 <$ (Lua.pushnil *> Lua.pushnil)
443− (nextKey, pushValue):_ -> 2 <$ (Lua.push nextKey *> pushValue st)
444− _ -> 2 <$ (Lua.pushnil *> Lua.pushnil)
445−
446−commonStateFields :: [(String, CommonState -> Lua ())]
447−commonStateFields =
448− [ ("input_files", Lua.push . stInputFiles)
449− , ("output_file", Lua.push . Lua.Optional . stOutputFile)
450− , ("log", Lua.push . stLog)
451− , ("request_headers", Lua.push . Map.fromList . stRequestHeaders)
452− , ("resource_path", Lua.push . stResourcePath)
453− , ("source_url", Lua.push . Lua.Optional . stSourceURL)
454− , ("user_data_dir", Lua.push . Lua.Optional . stUserDataDir)
455− , ("trace", Lua.push . stTrace)
456− , ("verbosity", Lua.push . show . stVerbosity)
457− ]
458−
459−-- | Name used by Lua for the @CommonState@ type.
460−logMessageTypeName :: String
461−logMessageTypeName = "Pandoc LogMessage"
462−
463−instance Peekable LogMessage where
464− peek idx = reportValueOnFailure logMessageTypeName
465− (`toAnyWithName` logMessageTypeName) idx
466−
467−instance Pushable LogMessage where
468− push msg = pushAnyWithMetatable pushLogMessageMetatable msg
469− where
470− pushLogMessageMetatable = ensureUserdataMetatable logMessageTypeName $
471− LuaUtil.addFunction "__tostring" tostringLogMessage
472−
473−tostringLogMessage :: LogMessage -> Lua String
474−tostringLogMessage = return . showLogMessage
src/Text/Pandoc/Lua/Marshaling/AnyValue.hsnew file+26
@@ -0,0 +1,26 @@
1+{-# LANGUAGE NoImplicitPrelude #-}
2+{- |
3+ Module : Text.Pandoc.Lua.Marshaling.AnyValue
4+ Copyright : © 2017-2019 Albert Krewinkel
5+ License : GNU GPL, version 2 or above
6+
7+ Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
8+ Stability : alpha
9+
10+Helper type to work with raw Lua stack indices instead of unmarshaled
11+values.
12+
13+TODO: Most of this module should be abstracted, factored out, and go
14+into HsLua.
15+-}
16+module Text.Pandoc.Lua.Marshaling.AnyValue (AnyValue (..)) where
17+
18+import Prelude
19+import Foreign.Lua (Peekable (peek), StackIndex)
20+
21+-- | Dummy type to allow values of arbitrary Lua type. This just wraps
22+-- stack indices, using it requires extra care.
23+newtype AnyValue = AnyValue StackIndex
24+
25+instance Peekable AnyValue where
26+ peek = return . AnyValue
src/Text/Pandoc/Lua/Marshaling/CommonState.hsnew file+102
@@ -0,0 +1,102 @@
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
2+{-# LANGUAGE LambdaCase #-}
3+{-# LANGUAGE NoImplicitPrelude #-}
4+{- |
5+ Module : Text.Pandoc.Lua.Marshaling.CommonState
6+ Copyright : © 2012-2019 John MacFarlane
7+ © 2017-2019 Albert Krewinkel
8+ License : GNU GPL, version 2 or above
9+ Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
10+ Stability : alpha
11+
12+Instances to marshal (push) and unmarshal (peek) the common state.
13+-}
14+module Text.Pandoc.Lua.Marshaling.CommonState () where
15+
16+import Prelude
17+import Foreign.Lua (Lua, Peekable, Pushable)
18+import Foreign.Lua.Types.Peekable (reportValueOnFailure)
19+import Foreign.Lua.Userdata (ensureUserdataMetatable, pushAnyWithMetatable,
20+ toAnyWithName)
21+import Text.Pandoc.Class (CommonState (..))
22+import Text.Pandoc.Logging (LogMessage, showLogMessage)
23+import Text.Pandoc.Lua.Marshaling.AnyValue (AnyValue (..))
24+
25+import qualified Data.Map as Map
26+import qualified Foreign.Lua as Lua
27+import qualified Text.Pandoc.Lua.Util as LuaUtil
28+
29+-- | Name used by Lua for the @CommonState@ type.
30+commonStateTypeName :: String
31+commonStateTypeName = "Pandoc CommonState"
32+
33+instance Peekable CommonState where
34+ peek idx = reportValueOnFailure commonStateTypeName
35+ (`toAnyWithName` commonStateTypeName) idx
36+
37+instance Pushable CommonState where
38+ push st = pushAnyWithMetatable pushCommonStateMetatable st
39+ where
40+ pushCommonStateMetatable = ensureUserdataMetatable commonStateTypeName $ do
41+ LuaUtil.addFunction "__index" indexCommonState
42+ LuaUtil.addFunction "__pairs" pairsCommonState
43+
44+indexCommonState :: CommonState -> AnyValue -> Lua Lua.NumResults
45+indexCommonState st (AnyValue idx) = Lua.ltype idx >>= \case
46+ Lua.TypeString -> 1 <$ (Lua.peek idx >>= pushField)
47+ _ -> 1 <$ Lua.pushnil
48+ where
49+ pushField :: String -> Lua ()
50+ pushField name = case lookup name commonStateFields of
51+ Just pushValue -> pushValue st
52+ Nothing -> Lua.pushnil
53+
54+pairsCommonState :: CommonState -> Lua Lua.NumResults
55+pairsCommonState st = do
56+ Lua.pushHaskellFunction nextFn
57+ Lua.pushnil
58+ Lua.pushnil
59+ return 3
60+ where
61+ nextFn :: AnyValue -> AnyValue -> Lua Lua.NumResults
62+ nextFn _ (AnyValue idx) =
63+ Lua.ltype idx >>= \case
64+ Lua.TypeNil -> case commonStateFields of
65+ [] -> 2 <$ (Lua.pushnil *> Lua.pushnil)
66+ (key, pushValue):_ -> 2 <$ (Lua.push key *> pushValue st)
67+ Lua.TypeString -> do
68+ key <- Lua.peek idx
69+ case tail $ dropWhile ((/= key) . fst) commonStateFields of
70+ [] -> 2 <$ (Lua.pushnil *> Lua.pushnil)
71+ (nextKey, pushValue):_ -> 2 <$ (Lua.push nextKey *> pushValue st)
72+ _ -> 2 <$ (Lua.pushnil *> Lua.pushnil)
73+
74+commonStateFields :: [(String, CommonState -> Lua ())]
75+commonStateFields =
76+ [ ("input_files", Lua.push . stInputFiles)
77+ , ("output_file", Lua.push . Lua.Optional . stOutputFile)
78+ , ("log", Lua.push . stLog)
79+ , ("request_headers", Lua.push . Map.fromList . stRequestHeaders)
80+ , ("resource_path", Lua.push . stResourcePath)
81+ , ("source_url", Lua.push . Lua.Optional . stSourceURL)
82+ , ("user_data_dir", Lua.push . Lua.Optional . stUserDataDir)
83+ , ("trace", Lua.push . stTrace)
84+ , ("verbosity", Lua.push . show . stVerbosity)
85+ ]
86+
87+-- | Name used by Lua for the @CommonState@ type.
88+logMessageTypeName :: String
89+logMessageTypeName = "Pandoc LogMessage"
90+
91+instance Peekable LogMessage where
92+ peek idx = reportValueOnFailure logMessageTypeName
93+ (`toAnyWithName` logMessageTypeName) idx
94+
95+instance Pushable LogMessage where
96+ push msg = pushAnyWithMetatable pushLogMessageMetatable msg
97+ where
98+ pushLogMessageMetatable = ensureUserdataMetatable logMessageTypeName $
99+ LuaUtil.addFunction "__tostring" tostringLogMessage
100+
101+tostringLogMessage :: LogMessage -> Lua String
102+tostringLogMessage = return . showLogMessage
src/Text/Pandoc/Lua/Marshaling/ReaderOptions.hsnew file+79
@@ -0,0 +1,79 @@
1+{-# LANGUAGE NoImplicitPrelude #-}
2+{-# LANGUAGE FlexibleInstances #-}
3+{-# LANGUAGE ScopedTypeVariables #-}
4+{-# LANGUAGE LambdaCase #-}
5+{-# OPTIONS_GHC -fno-warn-orphans #-}
6+{- |
7+ Module : Text.Pandoc.Lua.Marshaling.ReaderOptions
8+ Copyright : © 2012-2019 John MacFarlane
9+ © 2017-2019 Albert Krewinkel
10+ License : GNU GPL, version 2 or above
11+
12+ Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
13+ Stability : alpha
14+
15+Marshaling instance for ReaderOptions and its components.
16+-}
17+module Text.Pandoc.Lua.Marshaling.ReaderOptions () where
18+
19+import Prelude
20+import Data.Data (showConstr, toConstr)
21+import Foreign.Lua (Lua, Pushable)
22+import Text.Pandoc.Extensions (Extensions)
23+import Text.Pandoc.Lua.Marshaling.AnyValue (AnyValue (..))
24+import Text.Pandoc.Lua.Marshaling.CommonState ()
25+import Text.Pandoc.Options (ReaderOptions (..), TrackChanges)
26+
27+import qualified Data.Set as Set
28+import qualified Foreign.Lua as Lua
29+import qualified Text.Pandoc.Lua.Util as LuaUtil
30+
31+--
32+-- Reader Options
33+--
34+instance Pushable Extensions where
35+ push exts = Lua.push (show exts)
36+
37+instance Pushable TrackChanges where
38+ push = Lua.push . showConstr . toConstr
39+
40+instance Pushable ReaderOptions where
41+ push ro = do
42+ let ReaderOptions
43+ (extensions :: Extensions)
44+ (standalone :: Bool)
45+ (columns :: Int)
46+ (tabStop :: Int)
47+ (indentedCodeClasses :: [String])
48+ (abbreviations :: Set.Set String)
49+ (defaultImageExtension :: String)
50+ (trackChanges :: TrackChanges)
51+ (stripComments :: Bool)
52+ = ro
53+ Lua.newtable
54+ LuaUtil.addField "extensions" extensions
55+ LuaUtil.addField "standalone" standalone
56+ LuaUtil.addField "columns" columns
57+ LuaUtil.addField "tab_stop" tabStop
58+ LuaUtil.addField "indented_code_classes" indentedCodeClasses
59+ LuaUtil.addField "abbreviations" abbreviations
60+ LuaUtil.addField "default_image_extension" defaultImageExtension
61+ LuaUtil.addField "track_changes" trackChanges
62+ LuaUtil.addField "strip_comments" stripComments
63+
64+ -- add metatable
65+ let indexReaderOptions :: AnyValue -> AnyValue -> Lua Lua.NumResults
66+ indexReaderOptions _tbl (AnyValue key) = do
67+ Lua.ltype key >>= \case
68+ Lua.TypeString -> Lua.peek key >>= \case
69+ "defaultImageExtension" -> Lua.push defaultImageExtension
70+ "indentedCodeClasses" -> Lua.push indentedCodeClasses
71+ "stripComments" -> Lua.push stripComments
72+ "tabStop" -> Lua.push tabStop
73+ "trackChanges" -> Lua.push trackChanges
74+ _ -> Lua.pushnil
75+ _ -> Lua.pushnil
76+ return 1
77+ Lua.newtable
78+ LuaUtil.addFunction "__index" indexReaderOptions
79+ Lua.setmetatable (Lua.nthFromTop 2)
src/Text/Pandoc/Lua/Module/MediaBag.hs+1−1
@@ -36,7 +36,7 @@ import Data.Maybe (fromMaybe)
36import Foreign.Lua (Lua, NumResults, Optional, liftIO)
36import Foreign.Lua (Lua, NumResults, Optional, liftIO)
37import Text.Pandoc.Class (CommonState (..), fetchItem, putCommonState,
37import Text.Pandoc.Class (CommonState (..), fetchItem, putCommonState,
38 runIOorExplode, setMediaBag)
38 runIOorExplode, setMediaBag)
39−import Text.Pandoc.Lua.StackInstances ()
39+import Text.Pandoc.Lua.Marshaling ()
40import Text.Pandoc.Lua.Util (addFunction)
40import Text.Pandoc.Lua.Util (addFunction)
41import Text.Pandoc.MIME (MimeType)
41import Text.Pandoc.MIME (MimeType)
42
42
src/Text/Pandoc/Lua/Module/Pandoc.hs+1−1
@@ -41,7 +41,7 @@ import System.Exit (ExitCode (..))
41import Text.Pandoc.Class (runIO)
41import Text.Pandoc.Class (runIO)
42import Text.Pandoc.Definition (Block, Inline)
42import Text.Pandoc.Definition (Block, Inline)
43import Text.Pandoc.Lua.Filter (walkInlines, walkBlocks, LuaFilter)
43import Text.Pandoc.Lua.Filter (walkInlines, walkBlocks, LuaFilter)
44−import Text.Pandoc.Lua.StackInstances ()
44+import Text.Pandoc.Lua.Marshaling ()
45import Text.Pandoc.Walk (Walkable)
45import Text.Pandoc.Walk (Walkable)
46import Text.Pandoc.Options (ReaderOptions (readerExtensions))
46import Text.Pandoc.Options (ReaderOptions (readerExtensions))
47import Text.Pandoc.Process (pipeProcess)
47import Text.Pandoc.Process (pipeProcess)
src/Text/Pandoc/Lua/Module/Utils.hs+1−1
@@ -38,7 +38,7 @@ import Foreign.Lua (Peekable, Lua, NumResults)
38import Text.Pandoc.Class (runIO, setUserDataDir)
38import Text.Pandoc.Class (runIO, setUserDataDir)
39import Text.Pandoc.Definition ( Pandoc, Meta, MetaValue (..), Block, Inline
39import Text.Pandoc.Definition ( Pandoc, Meta, MetaValue (..), Block, Inline
40 , Citation, Attr, ListAttributes)
40 , Citation, Attr, ListAttributes)
41−import Text.Pandoc.Lua.StackInstances ()
41+import Text.Pandoc.Lua.Marshaling ()
42import Text.Pandoc.Lua.Util (addFunction)
42import Text.Pandoc.Lua.Util (addFunction)
43
43
44import qualified Data.Digest.Pure.SHA as SHA
44import qualified Data.Digest.Pure.SHA as SHA