diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2019-05-04 07:06:30 +0200 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-05-04 01:06:30 -0400 |
commit | 786594b23be4a757e95776f782527c8a98fbaab5 (patch) | |
tree | 6cf961b47a7d9df096be0347497a56c26b160aa8 /src/Text/Pandoc/Lua/Module | |
parent | 4f260c96d9b84fb90d4e9b7c611556b1708b90fe (diff) | |
download | pandoc-786594b23be4a757e95776f782527c8a98fbaab5.tar.gz |
Lua: add `pandoc.system` module (#5468)
The `system` Lua module provides utility functions to interact with the
operating- and file system. E.g.
print(pandoc.system.get_current_directory())
or
pandoc.system.with_temporary_directory('tikz', function (dir)
-- write and compile a TikZ file with pdflatex
end)
Diffstat (limited to 'src/Text/Pandoc/Lua/Module')
-rw-r--r-- | src/Text/Pandoc/Lua/Module/System.hs | 34 |
1 files changed, 34 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 |