@@ -34,10 +34,11 @@ module Text.Pandoc.Lua.StackInstances () where
35import Control.Applicative ( (<|>) )
35import Control.Applicative ( (<|>) )
36import Scripting.Lua
36import Scripting.Lua
37− ( LTYPE(..), LuaState, StackValue(..), getglobal2, ltype, newtable, objlen )
37+ ( LTYPE(..), LuaState, StackValue(..), ltype, newtable, objlen )
38import Text.Pandoc.Definition
38import Text.Pandoc.Definition
39import Text.Pandoc.Lua.SharedInstances ()
39import Text.Pandoc.Lua.SharedInstances ()
40import Text.Pandoc.Lua.Util ( addValue, getTable, pushViaConstructor )
40import Text.Pandoc.Lua.Util ( addValue, getTable, pushViaConstructor )
41+import Text.Pandoc.Shared ( safeRead )
42instance StackValue Pandoc where
43instance StackValue Pandoc where
43 push lua (Pandoc meta blocks) = do
44 push lua (Pandoc meta blocks) = do
@@ -143,19 +144,8 @@ instance StackValue Inline where
143 valuetype _ = TTABLE
144 valuetype _ = TTABLE
145instance StackValue Alignment where
146instance StackValue Alignment where
146− push lua = \case
147+ push lua = push lua . show
147− AlignLeft -> getglobal2 lua "pandoc.AlignLeft"
148− AlignRight -> getglobal2 lua "pandoc.AlignRight"
149− AlignCenter -> getglobal2 lua "pandoc.AlignCenter"
150− AlignDefault -> getglobal2 lua "pandoc.AlignDefault"
151− peek lua idx = do
148+ peek lua idx = (>>= safeRead) <$> peek lua idx
152− tag <- getTable lua idx "t"
154− Just "AlignLeft" -> return $ Just AlignLeft
155− Just "AlignRight" -> return $ Just AlignRight
156− Just "AlignCenter" -> return $ Just AlignCenter
157− Just "AlignDefault" -> return $ Just AlignDefault
159 valuetype _ = TSTRING
149 valuetype _ = TSTRING
161instance StackValue Citation where
151instance StackValue Citation where
@@ -172,18 +162,9 @@ instance StackValue Citation where
172 valuetype _ = TTABLE
162 valuetype _ = TTABLE
174instance StackValue CitationMode where
164instance StackValue CitationMode where
175− push lua = \case
165+ push lua = push lua . show
176− AuthorInText -> getglobal2 lua "pandoc.AuthorInText"
177− NormalCitation -> getglobal2 lua "pandoc.NormalCitation"
178− SuppressAuthor -> getglobal2 lua "pandoc.SuppressAuthor"
179− peek lua idx = do
166+ peek lua idx = (>>= safeRead) <$> peek lua idx
180− tag <- getTable lua idx "t"
182− Just "AuthorInText" -> return $ Just AuthorInText
183− Just "NormalCitation" -> return $ Just NormalCitation
184− Just "SuppressAuthor" -> return $ Just SuppressAuthor
186− valuetype _ = TTABLE
167+ valuetype _ = TSTRING
188instance StackValue Format where
169instance StackValue Format where
189 push lua (Format f) = push lua f
170 push lua (Format f) = push lua f
@@ -191,66 +172,24 @@ instance StackValue Format where
191 valuetype _ = TSTRING
172 valuetype _ = TSTRING
193instance StackValue ListNumberDelim where
174instance StackValue ListNumberDelim where
194− push lua = \case
175+ push lua = push lua . show
195− DefaultDelim -> getglobal2 lua "pandoc.DefaultDelim"
196− Period -> getglobal2 lua "pandoc.Period"
197− OneParen -> getglobal2 lua "pandoc.OneParen"
198− TwoParens -> getglobal2 lua "pandoc.TwoParens"
199− peek lua idx = do
176+ peek lua idx = (>>= safeRead) <$> peek lua idx
200− tag <- getTable lua idx "t"
202− Just "DefaultDelim" -> return $ Just DefaultDelim
203− Just "Period" -> return $ Just Period
204− Just "OneParen" -> return $ Just OneParen
205− Just "TwoParens" -> return $ Just TwoParens
207− valuetype _ = TTABLE
177+ valuetype _ = TSTRING
209instance StackValue ListNumberStyle where
179instance StackValue ListNumberStyle where
210− push lua = \case
180+ push lua = push lua . show
211− DefaultStyle -> getglobal2 lua "pandoc.DefaultStyle"
212− LowerRoman -> getglobal2 lua "pandoc.LowerRoman"
213− UpperRoman -> getglobal2 lua "pandoc.UpperRoman"
214− LowerAlpha -> getglobal2 lua "pandoc.LowerAlpha"
215− UpperAlpha -> getglobal2 lua "pandoc.UpperAlpha"
216− Decimal -> getglobal2 lua "pandoc.Decimal"
217− Example -> getglobal2 lua "pandoc.Example"
218− peek lua idx = do
181+ peek lua idx = (>>= safeRead) <$> peek lua idx
219− tag <- getTable lua idx "t"
221− Just "DefaultStyle" -> return $ Just DefaultStyle
222− Just "LowerRoman" -> return $ Just LowerRoman
223− Just "UpperRoman" -> return $ Just UpperRoman
224− Just "LowerAlpha" -> return $ Just LowerAlpha
225− Just "UpperAlpha" -> return $ Just UpperAlpha
226− Just "Decimal" -> return $ Just Decimal
227− Just "Example" -> return $ Just Example
229− valuetype _ = TTABLE
182+ valuetype _ = TSTRING
231instance StackValue MathType where
184instance StackValue MathType where
232− push lua = \case
185+ push lua = push lua . show
233− InlineMath -> getglobal2 lua "pandoc.InlineMath"
234− DisplayMath -> getglobal2 lua "pandoc.DisplayMath"
235− peek lua idx = do
186+ peek lua idx = (>>= safeRead) <$> peek lua idx
236− res <- getTable lua idx "t"
238− Just "InlineMath" -> return $ Just InlineMath
239− Just "DisplayMath" -> return $ Just DisplayMath
241− valuetype _ = TTABLE
187+ valuetype _ = TSTRING
243instance StackValue QuoteType where
189instance StackValue QuoteType where
244− push lua = \case
190+ push lua = push lua . show
245− SingleQuote -> getglobal2 lua "pandoc.SingleQuote"
246− DoubleQuote -> getglobal2 lua "pandoc.DoubleQuote"
247− peek lua idx = do
191+ peek lua idx = (>>= safeRead) <$> peek lua idx
248− res <- getTable lua idx "t"
250− Just "SingleQuote" -> return $ Just SingleQuote
251− Just "DoubleQuote" -> return $ Just DoubleQuote
253− valuetype _ = TTABLE
192+ valuetype _ = TSTRING
255-- | Return the value at the given index as inline if possible.
194-- | Return the value at the given index as inline if possible.
256peekInline :: LuaState -> Int -> IO (Maybe Inline)
195peekInline :: LuaState -> Int -> IO (Maybe Inline)