@@ -33,8 +33,8 @@ StackValue instances for pandoc types.
3333module Text.Pandoc.Lua.StackInstances () where
3434
3535import Control.Applicative ((<|>))
36−import Foreign.Lua (Lua, Type (..), FromLuaStack (peek), ToLuaStack (push),
37− StackIndex, throwLuaError, tryLua)
36+import Foreign.Lua (Lua, LuaInteger, LuaNumber, Type (..), FromLuaStack (peek),
37+ ToLuaStack (push), StackIndex, throwLuaError, tryLua)
3838import Foreign.Lua.Api (getmetatable, ltype, newtable, pop, rawget, rawlen)
3939import Text.Pandoc.Definition
4040import Text.Pandoc.Lua.Util (addValue, adjustIndexBy, getTable, pushViaConstructor)
@@ -125,6 +125,16 @@ instance ToLuaStack QuoteType where
125125instance FromLuaStack QuoteType where
126126 peek idx = safeRead' =<< peek idx
127127
128+instance ToLuaStack Double where
129+ push = push . (realToFrac :: Double -> LuaNumber)
130+instance FromLuaStack Double where
131+ peek = fmap (realToFrac :: LuaNumber -> Double) . peek
132+
133+instance ToLuaStack Int where
134+ push = push . (fromIntegral :: Int -> LuaInteger)
135+instance FromLuaStack Int where
136+ peek = fmap (fromIntegral :: LuaInteger-> Int) . peek
137+
128138safeRead' :: Read a => String -> Lua a
129139safeRead' s = case safeRead s of
130140 Nothing -> throwLuaError ("Could not read: " ++ s)