aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua/StackInstances.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Lua/StackInstances.hs')
-rw-r--r--src/Text/Pandoc/Lua/StackInstances.hs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Lua/StackInstances.hs b/src/Text/Pandoc/Lua/StackInstances.hs
index da9c33183..15a7cdd84 100644
--- a/src/Text/Pandoc/Lua/StackInstances.hs
+++ b/src/Text/Pandoc/Lua/StackInstances.hs
@@ -33,8 +33,8 @@ StackValue instances for pandoc types.
module Text.Pandoc.Lua.StackInstances () where
import Control.Applicative ((<|>))
-import Foreign.Lua (Lua, Type (..), FromLuaStack (peek), ToLuaStack (push),
- StackIndex, throwLuaError, tryLua)
+import Foreign.Lua (Lua, LuaInteger, LuaNumber, Type (..), FromLuaStack (peek),
+ ToLuaStack (push), StackIndex, throwLuaError, tryLua)
import Foreign.Lua.Api (getmetatable, ltype, newtable, pop, rawget, rawlen)
import Text.Pandoc.Definition
import Text.Pandoc.Lua.Util (addValue, adjustIndexBy, getTable, pushViaConstructor)
@@ -125,6 +125,16 @@ instance ToLuaStack QuoteType where
instance FromLuaStack QuoteType where
peek idx = safeRead' =<< peek idx
+instance ToLuaStack Double where
+ push = push . (realToFrac :: Double -> LuaNumber)
+instance FromLuaStack Double where
+ peek = fmap (realToFrac :: LuaNumber -> Double) . peek
+
+instance ToLuaStack Int where
+ push = push . (fromIntegral :: Int -> LuaInteger)
+instance FromLuaStack Int where
+ peek = fmap (fromIntegral :: LuaInteger-> Int) . peek
+
safeRead' :: Read a => String -> Lua a
safeRead' s = case safeRead s of
Nothing -> throwLuaError ("Could not read: " ++ s)