@@ -35,28 +35,22 @@ StackValue instances for pandoc types.
36module Text.Pandoc.Lua.StackInstances () where
36module Text.Pandoc.Lua.StackInstances () where
38−import Data.Aeson ( FromJSON(..), ToJSON(..), Result(..), Value, fromJSON )
38+import Control.Applicative ( (<|>) )
39import Scripting.Lua
39import Scripting.Lua
40 ( LTYPE(..), LuaState, StackValue(..)
40 ( LTYPE(..), LuaState, StackValue(..)
41+ , call, getglobal2, gettable, ltype, newtable, next, objlen
41− , gettable, newtable, pop, rawgeti, rawset, rawseti, settable
42+ , pop, pushnil, rawgeti, rawseti, settable
43−import Scripting.Lua.Aeson ()
44import Text.Pandoc.Definition
44import Text.Pandoc.Definition
45− ( Block(..), Inline(..), Meta(..), Pandoc(..)
46− , Citation(..), CitationMode(..), Format(..), MathType(..), QuoteType(..) )
46+import qualified Data.Map as M
48import qualified Text.Pandoc.UTF8 as UTF8
47import qualified Text.Pandoc.UTF8 as UTF8
50−maybeFromJson :: (FromJSON a) => Maybe Value -> Maybe a
51−maybeFromJson mv = fromJSON <$> mv >>= \case
55instance StackValue Pandoc where
49instance StackValue Pandoc where
56 push lua (Pandoc meta blocks) = do
50 push lua (Pandoc meta blocks) = do
57 newtable lua
51 newtable lua
58− setField lua (-1) "blocks" blocks
52+ addKeyValue lua "blocks" blocks
59− setField lua (-1) "meta" meta
53+ addKeyValue lua "meta" meta
60 peek lua idx = do
54 peek lua idx = do
61 blocks <- getField lua idx "blocks"
55 blocks <- getField lua idx "blocks"
62 meta <- getField lua idx "meta"
56 meta <- getField lua idx "meta"
@@ -64,57 +58,122 @@ instance StackValue Pandoc where
64 valuetype _ = TTABLE
58 valuetype _ = TTABLE
66instance StackValue Meta where
60instance StackValue Meta where
67− push lua = push lua . toJSON
61+ push lua (Meta mmap) = push lua mmap
68− peek lua = fmap maybeFromJson . peek lua
62+ peek lua idx = fmap Meta <$> peek lua idx
69 valuetype _ = TTABLE
63 valuetype _ = TTABLE
65+instance StackValue MetaValue where
67+ MetaBlocks blcks -> pushViaConstructor lua "MetaBlocks" blcks
68+ MetaBool b -> pushViaConstructor lua "MetaBool" b
69+ MetaInlines inlns -> pushViaConstructor lua "MetaInlines" inlns
70+ MetaList metalist -> pushViaConstructor lua "MetaList" metalist
71+ MetaMap metamap -> pushViaConstructor lua "MetaMap" metamap
72+ MetaString cs -> pushViaConstructor lua "MetaString" cs
74+ luatype <- ltype lua idx
76+ TBOOLEAN -> fmap MetaBool <$> peek lua idx
77+ TSTRING -> fmap MetaString <$> peek lua idx
80+ *> gettable lua (idx `adjustIndexBy` 1)
84+ Just "MetaBlocks" -> fmap MetaBlocks <$> peekContent lua idx
85+ Just "MetaBool" -> fmap MetaBool <$> peekContent lua idx
86+ Just "MetaMap" -> fmap MetaMap <$> peekContent lua idx
87+ Just "MetaInlines" -> fmap MetaInlines <$> peekContent lua idx
88+ Just "MetaList" -> fmap MetaList <$> peekContent lua idx
89+ Just "MetaString" -> fmap MetaString <$> peekContent lua idx
91+ len <- objlen lua idx
93+ then fmap MetaMap <$> peek lua idx
94+ else (fmap MetaInlines <$> peek lua idx)
95+ <|> (fmap MetaBlocks <$> peek lua idx)
96+ <|> (fmap MetaList <$> peek lua idx)
100+ MetaBlocks _ -> TTABLE
101+ MetaBool _ -> TBOOLEAN
102+ MetaInlines _ -> TTABLE
103+ MetaList _ -> TTABLE
105+ MetaString _ -> TSTRING
107+peekContent :: StackValue a => LuaState -> Int -> IO (Maybe a)
108+peekContent lua idx = do
110+ gettable lua (idx `adjustIndexBy` 1)
111+ peek lua (-1) <* pop lua 1
71instance StackValue Block where
113instance StackValue Block where
72 push lua = \case
114 push lua = \case
73− BlockQuote blcks -> pushTagged lua "BlockQuote" blcks
115+ BlockQuote blcks -> pushViaConstructor lua "BlockQuote" blcks
74− BulletList items -> pushTagged lua "BulletList" items
116+ BulletList items -> pushViaConstructor lua "BulletList" items
117+ CodeBlock attr code -> pushViaConstructor lua "CodeBlock" code attr
118+ DefinitionList items -> pushViaConstructor lua "DefinitionList" items
119+ Div attr blcks -> pushViaConstructor lua "Div" blcks attr
120+ Header lvl attr inlns -> pushViaConstructor lua "Header" lvl attr inlns
75− HorizontalRule -> pushTagged' lua "HorizontalRule"
121+ HorizontalRule -> pushViaConstructor lua "HorizontalRule"
76− LineBlock blcks -> pushTagged lua "LineBlock" blcks
122+ LineBlock blcks -> pushViaConstructor lua "LineBlock" blcks
77− Null -> pushTagged' lua "Null"
123+ OrderedList lstAttr list -> pushViaConstructor lua "OrderedList" list lstAttr
78− Para blcks -> pushTagged lua "Para" blcks
124+ Null -> pushViaConstructor lua "Null"
79− Plain blcks -> pushTagged lua "Plain" blcks
125+ Para blcks -> pushViaConstructor lua "Para" blcks
126+ Plain blcks -> pushViaConstructor lua "Plain" blcks
127+ RawBlock f cs -> pushViaConstructor lua "RawBlock" f cs
128+ Table capt aligns widths headers rows ->
129+ pushViaConstructor lua "Table" capt aligns widths headers rows
80 -- fall back to conversion via aeson's Value
130 -- fall back to conversion via aeson's Value
81− x -> push lua (toJSON x)
82 peek lua i = peekBlock lua i
131 peek lua i = peekBlock lua i
83 valuetype _ = TTABLE
132 valuetype _ = TTABLE
85instance StackValue Inline where
134instance StackValue Inline where
86 push lua = \case
135 push lua = \case
87− Cite citations lst -> pushTagged lua "Cite" (citations, lst)
136+ Cite citations lst -> pushViaConstructor lua "Cite" lst citations
88− Code attr lst -> pushTagged lua "Code" (attr, lst)
137+ Code attr lst -> pushViaConstructor lua "Code" lst attr
89− Emph inlns -> pushTagged lua "Emph" inlns
138+ Emph inlns -> pushViaConstructor lua "Emph" inlns
90− Image attr lst tgt -> pushTagged lua "Image" (attr, lst, tgt)
139+ Image attr alt (src,tit) -> pushViaConstructor lua "Image" alt src tit attr
91− LineBreak -> pushTagged' lua "LineBreak"
140+ LineBreak -> pushViaConstructor lua "LineBreak"
92− Link attr lst tgt -> pushTagged lua "Link" (attr, lst, tgt)
141+ Link attr lst (src,tit) -> pushViaConstructor lua "Link" lst src tit attr
93− Note blcks -> pushTagged lua "Note" blcks
142+ Note blcks -> pushViaConstructor lua "Note" blcks
94− Math mty str -> pushTagged lua "Math" (mty, str)
143+ Math mty str -> pushViaConstructor lua "Math" mty str
95− Quoted qt inlns -> pushTagged lua "Quoted" (qt, inlns)
144+ Quoted qt inlns -> pushViaConstructor lua "Quoted" qt inlns
96− RawInline f cs -> pushTagged lua "RawInline" (f, cs)
145+ RawInline f cs -> pushViaConstructor lua "RawInline" f cs
97− SmallCaps inlns -> pushTagged lua "SmallCaps" inlns
146+ SmallCaps inlns -> pushViaConstructor lua "SmallCaps" inlns
98− SoftBreak -> pushTagged' lua "SoftBreak"
147+ SoftBreak -> pushViaConstructor lua "SoftBreak"
99− Space -> pushTagged' lua "Space"
148+ Space -> pushViaConstructor lua "Space"
100− Span attr inlns -> pushTagged lua "Span" (attr, inlns)
149+ Span attr inlns -> pushViaConstructor lua "Span" inlns attr
101− Str str -> pushTagged lua "Str" str
150+ Str str -> pushViaConstructor lua "Str" str
102− Strikeout inlns -> pushTagged lua "Strikeout" inlns
151+ Strikeout inlns -> pushViaConstructor lua "Strikeout" inlns
103− Strong inlns -> pushTagged lua "Strong" inlns
152+ Strong inlns -> pushViaConstructor lua "Strong" inlns
104− Subscript inlns -> pushTagged lua "Subscript" inlns
153+ Subscript inlns -> pushViaConstructor lua "Subscript" inlns
105− Superscript inlns -> pushTagged lua "Superscript" inlns
154+ Superscript inlns -> pushViaConstructor lua "Superscript" inlns
106 peek = peekInline
155 peek = peekInline
107 valuetype _ = TTABLE
156 valuetype _ = TTABLE
158+instance StackValue Alignment where
160+ AlignLeft -> getglobal2 lua "pandoc.AlignLeft"
161+ AlignRight -> getglobal2 lua "pandoc.AlignRight"
162+ AlignCenter -> getglobal2 lua "pandoc.AlignCenter"
163+ AlignDefault -> getglobal2 lua "pandoc.AlignDefault"
165+ tag <- getField lua idx "t"
167+ Just "AlignLeft" -> return $ Just AlignLeft
168+ Just "AlignRight" -> return $ Just AlignRight
169+ Just "AlignCenter" -> return $ Just AlignCenter
170+ Just "AlignDefault" -> return $ Just AlignDefault
172+ valuetype _ = TSTRING
109instance StackValue Citation where
174instance StackValue Citation where
110− push lua c = do
175+ push lua (Citation cid prefix suffix mode noteNum hash) =
111− newtable lua
176+ pushViaConstructor lua "Citation" cid mode prefix suffix noteNum hash
112− setField lua (-1) "citationId" (citationId c)
113− setField lua (-1) "citationPrefix" (citationPrefix c)
114− setField lua (-1) "citationSuffix" (citationSuffix c)
115− setField lua (-1) "citationMode" (citationMode c)
116− setField lua (-1) "citationNoteNum" (citationNoteNum c)
117− setField lua (-1) "citationHash" (citationHash c)
118 peek lua idx = do
177 peek lua idx = do
119 id' <- getField lua idx "citationId"
178 id' <- getField lua idx "citationId"
120 prefix <- getField lua idx "citationPrefix"
179 prefix <- getField lua idx "citationPrefix"
@@ -122,20 +181,14 @@ instance StackValue Citation where
122 mode <- getField lua idx "citationMode"
181 mode <- getField lua idx "citationMode"
123 num <- getField lua idx "citationNoteNum"
182 num <- getField lua idx "citationNoteNum"
124 hash <- getField lua idx "citationHash"
183 hash <- getField lua idx "citationHash"
125− return $ Citation
184+ return $ Citation <$> id' <*> prefix <*> suffix <*> mode <*> num <*> hash
132 valuetype _ = TTABLE
185 valuetype _ = TTABLE
134instance StackValue CitationMode where
187instance StackValue CitationMode where
135 push lua = \case
188 push lua = \case
136− AuthorInText -> pushTagged' lua "AuthorInText"
189+ AuthorInText -> getglobal2 lua "pandoc.AuthorInText"
137− NormalCitation -> pushTagged' lua "NormalCitation"
190+ NormalCitation -> getglobal2 lua "pandoc.NormalCitation"
138− SuppressAuthor -> pushTagged' lua "SuppressAuthor"
191+ SuppressAuthor -> getglobal2 lua "pandoc.SuppressAuthor"
139 peek lua idx = do
192 peek lua idx = do
140 tag <- getField lua idx "t"
193 tag <- getField lua idx "t"
141 case tag of
194 case tag of
@@ -143,17 +196,55 @@ instance StackValue CitationMode where
143 Just "NormalCitation" -> return $ Just NormalCitation
196 Just "NormalCitation" -> return $ Just NormalCitation
144 Just "SuppressAuthor" -> return $ Just SuppressAuthor
197 Just "SuppressAuthor" -> return $ Just SuppressAuthor
145 _ -> return Nothing
198 _ -> return Nothing
146− valuetype _ = TSTRING
199+ valuetype _ = TTABLE
148instance StackValue Format where
201instance StackValue Format where
149 push lua (Format f) = push lua f
202 push lua (Format f) = push lua f
150 peek lua idx = fmap Format <$> peek lua idx
203 peek lua idx = fmap Format <$> peek lua idx
151 valuetype _ = TSTRING
204 valuetype _ = TSTRING
206+instance StackValue ListNumberDelim where
208+ DefaultDelim -> getglobal2 lua "pandoc.DefaultDelim"
209+ Period -> getglobal2 lua "pandoc.Period"
210+ OneParen -> getglobal2 lua "pandoc.OneParen"
211+ TwoParens -> getglobal2 lua "pandoc.TwoParens"
213+ tag <- getField lua idx "t"
215+ Just "DefaultDelim" -> return $ Just DefaultDelim
216+ Just "Period" -> return $ Just Period
217+ Just "OneParen" -> return $ Just OneParen
218+ Just "TwoParens" -> return $ Just TwoParens
220+ valuetype _ = TTABLE
222+instance StackValue ListNumberStyle where
224+ DefaultStyle -> getglobal2 lua "pandoc.DefaultStyle"
225+ LowerRoman -> getglobal2 lua "pandoc.LowerRoman"
226+ UpperRoman -> getglobal2 lua "pandoc.UpperRoman"
227+ LowerAlpha -> getglobal2 lua "pandoc.LowerAlpha"
228+ UpperAlpha -> getglobal2 lua "pandoc.UpperAlpha"
229+ Decimal -> getglobal2 lua "pandoc.Decimal"
230+ Example -> getglobal2 lua "pandoc.Example"
232+ tag <- getField lua idx "t"
234+ Just "DefaultStyle" -> return $ Just DefaultStyle
235+ Just "LowerRoman" -> return $ Just LowerRoman
236+ Just "UpperRoman" -> return $ Just UpperRoman
237+ Just "LowerAlpha" -> return $ Just LowerAlpha
238+ Just "UpperAlpha" -> return $ Just UpperAlpha
239+ Just "Decimal" -> return $ Just Decimal
240+ Just "Example" -> return $ Just Example
242+ valuetype _ = TTABLE
153instance StackValue MathType where
244instance StackValue MathType where
154 push lua = \case
245 push lua = \case
155− InlineMath -> pushTagged' lua "InlineMath"
246+ InlineMath -> getglobal2 lua "pandoc.InlineMath"
156− DisplayMath -> pushTagged' lua "DisplayMath"
247+ DisplayMath -> getglobal2 lua "pandoc.DisplayMath"
157 peek lua idx = do
248 peek lua idx = do
158 res <- getField lua idx "t"
249 res <- getField lua idx "t"
159 case res of
250 case res of
@@ -164,8 +255,8 @@ instance StackValue MathType where
165instance StackValue QuoteType where
256instance StackValue QuoteType where
166 push lua = \case
257 push lua = \case
167− SingleQuote -> pushTagged' lua "SingleQuote"
258+ SingleQuote -> getglobal2 lua "pandoc.SingleQuote"
168− DoubleQuote -> pushTagged' lua "DoubleQuote"
259+ DoubleQuote -> getglobal2 lua "pandoc.DoubleQuote"
169 peek lua idx = do
260 peek lua idx = do
170 res <- getField lua idx "t"
261 res <- getField lua idx "t"
171 case res of
262 case res of
@@ -186,11 +277,11 @@ instance StackValue [Char] where
186instance (StackValue a, StackValue b) => StackValue (a, b) where
277instance (StackValue a, StackValue b) => StackValue (a, b) where
187 push lua (a, b) = do
278 push lua (a, b) = do
188 newtable lua
279 newtable lua
189− setIntField lua (-1) 1 a
280+ addIndexedValue lua 1 a
190− setIntField lua (-1) 2 b
281+ addIndexedValue lua 2 b
191 peek lua idx = do
282 peek lua idx = do
192− a <- getIntField lua idx 1
283+ a <- getIndexedValue lua idx 1
193− b <- getIntField lua idx 2
284+ b <- getIndexedValue lua idx 2
194 return $ (,) <$> a <*> b
285 return $ (,) <$> a <*> b
195 valuetype _ = TTABLE
286 valuetype _ = TTABLE
@@ -199,31 +290,93 @@ instance (StackValue a, StackValue b, StackValue c) =>
200 push lua (a, b, c) = do
291 push lua (a, b, c) = do
201 newtable lua
292 newtable lua
202− setIntField lua (-1) 1 a
293+ addIndexedValue lua 1 a
203− setIntField lua (-1) 2 b
294+ addIndexedValue lua 2 b
204− setIntField lua (-1) 3 c
295+ addIndexedValue lua 3 c
205 peek lua idx = do
296 peek lua idx = do
206− a <- getIntField lua idx 1
297+ a <- getIndexedValue lua idx 1
207− b <- getIntField lua idx 2
298+ b <- getIndexedValue lua idx 2
208− c <- getIntField lua idx 3
299+ c <- getIndexedValue lua idx 3
209 return $ (,,) <$> a <*> b <*> c
300 return $ (,,) <$> a <*> b <*> c
210 valuetype _ = TTABLE
301 valuetype _ = TTABLE
212−-- | Push a value to the lua stack, tagged with a given string. This currently
303+instance (StackValue a, StackValue b, StackValue c,
213−-- creates a structure equivalent to what the JSONified value would look like
304+ StackValue d, StackValue e) =>
214−-- when pushed to lua.
305+ StackValue (a, b, c, d, e)
307+ push lua (a, b, c, d, e) = do
309+ addIndexedValue lua 1 a
310+ addIndexedValue lua 2 b
311+ addIndexedValue lua 3 c
312+ addIndexedValue lua 4 d
313+ addIndexedValue lua 5 e
315+ a <- getIndexedValue lua idx 1
316+ b <- getIndexedValue lua idx 2
317+ c <- getIndexedValue lua idx 3
318+ d <- getIndexedValue lua idx 4
319+ e <- getIndexedValue lua idx 5
320+ return $ (,,,,) <$> a <*> b <*> c <*> d <*> e
321+ valuetype _ = TTABLE
323+instance (Ord a, StackValue a, StackValue b) =>
324+ StackValue (M.Map a b) where
327+ mapM_ (uncurry $ addKeyValue lua) $ M.toList m
328+ peek lua idx = fmap M.fromList <$> keyValuePairs lua idx
329+ valuetype _ = TTABLE
331+-- | Try reading the value under the given index as a list of key-value pairs.
332+keyValuePairs :: (StackValue a, StackValue b)
333+ => LuaState -> Int -> IO (Maybe [(a, b)])
334+keyValuePairs lua idx = do
336+ sequence <$> remainingPairs
341+ Nothing -> return []
342+ Just a -> (a:) <$> remainingPairs
343+ nextPair :: (StackValue a, StackValue b) => IO (Maybe (Maybe (a,b)))
345+ hasNext <- next lua (idx `adjustIndexBy` 1)
348+ val <- peek lua (-1)
349+ key <- peek lua (-2)
350+ pop lua 1 -- removes the value, keeps the key
351+ return $ Just <$> ((,) <$> key <*> val)
356+-- | Helper class for pushing a single value to the stack via a lua function.
357+-- See @pushViaCall@.
358+class PushViaCall a where
359+ pushViaCall' :: LuaState -> String -> IO () -> Int -> a
361+instance PushViaCall (IO ()) where
362+ pushViaCall' lua fn pushArgs num = do
367+instance (StackValue a, PushViaCall b) => PushViaCall (a -> b) where
368+ pushViaCall' lua fn pushArgs num x =
369+ pushViaCall' lua fn (pushArgs *> push lua x) (num + 1)
371+-- | Push an value to the stack via a lua function. The lua function is called
372+-- with all arguments that are passed to this function and is expected to return
215−pushTagged :: StackValue a => LuaState -> String -> a -> IO ()
374+pushViaCall :: PushViaCall a => LuaState -> String -> a
216−pushTagged lua tag value = do
375+pushViaCall lua fn = pushViaCall' lua fn (return ()) 0
218− setField lua (-1) "t" tag
377+-- | Call a pandoc element constructor within lua, passing all given arguments.
219− setField lua (-1) "c" value
378+pushViaConstructor :: PushViaCall a => LuaState -> String -> a
220−
379+pushViaConstructor lua pandocFn = pushViaCall lua ("pandoc." ++ pandocFn)
221−pushTagged' :: LuaState -> String -> IO ()
222−pushTagged' lua tag = do
228-- | Return the value at the given index as inline if possible.
381-- | Return the value at the given index as inline if possible.
229peekInline :: LuaState -> Int -> IO (Maybe Inline)
382peekInline :: LuaState -> Int -> IO (Maybe Inline)
@@ -268,13 +421,22 @@ peekBlock lua idx = do
268 Just t -> case t of
421 Just t -> case t of
269 "BlockQuote" -> fmap BlockQuote <$> elementContent
422 "BlockQuote" -> fmap BlockQuote <$> elementContent
270 "BulletList" -> fmap BulletList <$> elementContent
423 "BulletList" -> fmap BulletList <$> elementContent
424+ "CodeBlock" -> fmap (uncurry CodeBlock) <$> elementContent
425+ "DefinitionList" -> fmap DefinitionList <$> elementContent
426+ "Div" -> fmap (uncurry Div) <$> elementContent
427+ "Header" -> fmap (\(lvl, attr, lst) -> Header lvl attr lst)
271 "HorizontalRule" -> return (Just HorizontalRule)
429 "HorizontalRule" -> return (Just HorizontalRule)
272 "LineBlock" -> fmap LineBlock <$> elementContent
430 "LineBlock" -> fmap LineBlock <$> elementContent
431+ "OrderedList" -> fmap (uncurry OrderedList) <$> elementContent
273 "Null" -> return (Just Null)
432 "Null" -> return (Just Null)
274 "Para" -> fmap Para <$> elementContent
433 "Para" -> fmap Para <$> elementContent
275 "Plain" -> fmap Plain <$> elementContent
434 "Plain" -> fmap Plain <$> elementContent
276− -- fall back to construction via aeson's Value
435+ "RawBlock" -> fmap (uncurry RawBlock) <$> elementContent
277− _ -> maybeFromJson <$> peek lua idx
436+ "Table" -> fmap (\(capt, aligns, widths, headers, body) ->
437+ Table capt aligns widths headers body)
279 -- Get the contents of an AST element.
441 -- Get the contents of an AST element.
280 elementContent :: StackValue a => IO (Maybe a)
442 elementContent :: StackValue a => IO (Maybe a)
@@ -296,21 +458,29 @@ getField lua idx key = do
296 peek lua (-1) <* pop lua 1
458 peek lua (-1) <* pop lua 1
298-- | Set value for key for table at the given index
460-- | Set value for key for table at the given index
299−setField :: (StackValue a, StackValue b) => LuaState -> Int -> a -> b -> IO ()
461+setKeyValue :: (StackValue a, StackValue b) => LuaState -> Int -> a -> b -> IO ()
300−setField lua idx key value = do
462+setKeyValue lua idx key value = do
301 push lua key
463 push lua key
302 push lua value
464 push lua value
303 settable lua (idx `adjustIndexBy` 2)
465 settable lua (idx `adjustIndexBy` 2)
467+-- | Add a key-value pair to the table at the top of the stack
468+addKeyValue :: (StackValue a, StackValue b) => LuaState -> a -> b -> IO ()
469+addKeyValue lua = setKeyValue lua (-1)
305-- | Get value behind key from table at given index.
471-- | Get value behind key from table at given index.
306−getIntField :: StackValue a => LuaState -> Int -> Int -> IO (Maybe a)
472+getIndexedValue :: StackValue a => LuaState -> Int -> Int -> IO (Maybe a)
307−getIntField lua idx key =
473+getIndexedValue lua idx key =
308 rawgeti lua idx key
474 rawgeti lua idx key
309 *> peek lua (-1)
475 *> peek lua (-1)
310 <* pop lua 1
476 <* pop lua 1
312-- | Set numeric key/value in table at the given index
478-- | Set numeric key/value in table at the given index
313−setIntField :: StackValue a => LuaState -> Int -> Int -> a -> IO ()
479+setIndexedValue :: StackValue a => LuaState -> Int -> Int -> a -> IO ()
314−setIntField lua idx key value = do
480+setIndexedValue lua idx key value = do
315 push lua value
481 push lua value
316 rawseti lua (idx `adjustIndexBy` 1) key
482 rawseti lua (idx `adjustIndexBy` 1) key
484+-- | Set numeric key/value in table at the top of the stack.
485+addIndexedValue :: StackValue a => LuaState -> Int -> a -> IO ()
486+addIndexedValue lua = setIndexedValue lua (-1)