aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua/Module
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-05-29 12:05:04 -0400
committerGitHub <noreply@github.com>2019-05-29 12:05:04 -0400
commite871d65b67e2458c6146debddeaddb3c9773f67c (patch)
tree77665385be99be05e80f1cdbe5ea93c5e3f72baa /src/Text/Pandoc/Lua/Module
parent1de7b20ebbb198362ec0b4717f72d275fb34dd9c (diff)
parent505f5bf5d951a5c4342f7acce9bea5f260dc9d78 (diff)
downloadpandoc-e871d65b67e2458c6146debddeaddb3c9773f67c.tar.gz
Merge pull request #5526 from tarleb/richer-version-type
Lua: add Version type to simplify comparisons
Diffstat (limited to 'src/Text/Pandoc/Lua/Module')
-rw-r--r--src/Text/Pandoc/Lua/Module/Types.hs28
-rw-r--r--src/Text/Pandoc/Lua/Module/Utils.hs2
2 files changed, 30 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Lua/Module/Types.hs b/src/Text/Pandoc/Lua/Module/Types.hs
new file mode 100644
index 000000000..641bde7d6
--- /dev/null
+++ b/src/Text/Pandoc/Lua/Module/Types.hs
@@ -0,0 +1,28 @@
+{- |
+ Module : Text.Pandoc.Lua.Module.Types
+ Copyright : © 2019 Albert Krewinkel
+ License : GNU GPL, version 2 or above
+
+ Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
+ Stability : alpha
+
+Pandoc data type constructors.
+-}
+module Text.Pandoc.Lua.Module.Types
+ ( pushModule
+ ) where
+
+import Prelude
+import Data.Version (Version)
+import Foreign.Lua (Lua, NumResults)
+import Text.Pandoc.Lua.Marshaling.Version ()
+import Text.Pandoc.Lua.Util (addFunction)
+
+import qualified Foreign.Lua as Lua
+
+-- | Push the pandoc.system module on the Lua stack.
+pushModule :: Lua NumResults
+pushModule = do
+ Lua.newtable
+ addFunction "Version" (return :: Version -> Lua Version)
+ return 1
diff --git a/src/Text/Pandoc/Lua/Module/Utils.hs b/src/Text/Pandoc/Lua/Module/Utils.hs
index 7f201a4b2..21e3f5674 100644
--- a/src/Text/Pandoc/Lua/Module/Utils.hs
+++ b/src/Text/Pandoc/Lua/Module/Utils.hs
@@ -17,6 +17,7 @@ import Prelude
import Control.Applicative ((<|>))
import Data.Char (toLower)
import Data.Default (def)
+import Data.Version (Version)
import Foreign.Lua (Peekable, Lua, NumResults)
import Text.Pandoc.Class (runIO, setUserDataDir)
import Text.Pandoc.Definition ( Pandoc, Meta, MetaValue (..), Block, Inline
@@ -43,6 +44,7 @@ pushModule mbDatadir = do
addFunction "sha1" sha1
addFunction "stringify" stringify
addFunction "to_roman_numeral" toRomanNumeral
+ addFunction "Version" (return :: Version -> Lua Version)
return 1
-- | Squashes a list of blocks into inlines.