aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Lua/Module/System.hs34
-rw-r--r--src/Text/Pandoc/Lua/Packages.hs2
2 files changed, 36 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Lua/Module/System.hs b/src/Text/Pandoc/Lua/Module/System.hs
new file mode 100644
index 000000000..5149c2112
--- /dev/null
+++ b/src/Text/Pandoc/Lua/Module/System.hs
@@ -0,0 +1,34 @@
+{- |
+ Module : Text.Pandoc.Lua.Module.System
+ Copyright : © 2019 Albert Krewinkel
+ License : GNU GPL, version 2 or above
+
+ Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
+ Stability : alpha
+
+Pandoc's system Lua module.
+-}
+module Text.Pandoc.Lua.Module.System
+ ( pushModule
+ ) where
+
+import Prelude
+import Foreign.Lua (Lua, NumResults)
+import Foreign.Lua.Module.System (arch, env, getwd, os,
+ with_env, with_tmpdir, with_wd)
+import Text.Pandoc.Lua.Util (addFunction, addField)
+
+import qualified Foreign.Lua as Lua
+
+-- | Push the pandoc.system module on the Lua stack.
+pushModule :: Lua NumResults
+pushModule = do
+ Lua.newtable
+ addField "arch" arch
+ addField "os" os
+ addFunction "environment" env
+ addFunction "get_current_directory" getwd
+ addFunction "with_environment" with_env
+ addFunction "with_temp_directory" with_tmpdir
+ addFunction "with_working_directory" with_wd
+ return 1
diff --git a/src/Text/Pandoc/Lua/Packages.hs b/src/Text/Pandoc/Lua/Packages.hs
index fdfa2238a..5f2751f52 100644
--- a/src/Text/Pandoc/Lua/Packages.hs
+++ b/src/Text/Pandoc/Lua/Packages.hs
@@ -25,6 +25,7 @@ import Text.Pandoc.Class (readDataFile, runIO, setUserDataDir)
import qualified Foreign.Lua as Lua
import Text.Pandoc.Lua.Module.Pandoc as Pandoc
import Text.Pandoc.Lua.Module.MediaBag as MediaBag
+import Text.Pandoc.Lua.Module.System as System
import Text.Pandoc.Lua.Module.Utils as Utils
-- | Parameters used to create lua packages/modules.
@@ -52,6 +53,7 @@ pandocPackageSearcher pkgParams pkgName =
"pandoc" -> let datadir = luaPkgDataDir pkgParams
in pushWrappedHsFun (Pandoc.pushModule datadir)
"pandoc.mediabag" -> pushWrappedHsFun MediaBag.pushModule
+ "pandoc.system" -> pushWrappedHsFun System.pushModule
"pandoc.utils" -> let datadir = luaPkgDataDir pkgParams
in pushWrappedHsFun (Utils.pushModule datadir)
_ -> searchPureLuaLoader