@@ -17,21 +17,26 @@ module Foreign.Lua.Module.System
1717where
1818
1919import Control.Applicative ((<$>) )
20- import Control.Exception (IOException , catch , evaluate , try )
20+ import Control.Exception (IOException , try )
2121import Data.Maybe (fromMaybe )
2222import Foreign.Lua (Lua , NumResults (.. ), Optional (.. ), Peekable , Pushable ,
2323 StackIndex , ToHaskellFunction )
24- import System.IO.Error (IOError , isDoesNotExistError )
2524
25+ import qualified Data.Version
2626import qualified Foreign.Lua as Lua
2727import qualified System.Directory as Directory
2828import qualified System.Environment as Env
29+ import qualified System.Info as Info
2930import qualified System.IO.Temp as Temp
3031
3132-- | Pushes the @text@ module to the lua stack.
3233pushModule :: Lua NumResults
3334pushModule = do
3435 Lua. newtable
36+ addField " arch" Info. arch
37+ addField " compiler_name" Info. compilerName
38+ addField " compiler_version" (Data.Version. versionBranch Info. compilerVersion)
39+ addField " os" Info. os
3540 addFunction " chdir" chdir
3641 addFunction " currentdir" currentdir
3742 addFunction " env" env
@@ -57,6 +62,12 @@ addPackagePreloader name modulePusher = do
5762 Lua. setfield (- 2 ) name
5863 Lua. pop 1
5964
65+ addField :: Pushable a => String -> a -> Lua ()
66+ addField name value = do
67+ Lua. push name
68+ Lua. push value
69+ Lua. rawset (Lua. nthFromTop 3 )
70+
6071-- | Attach a function to the table at the top of the stack, using the
6172-- given name.
6273addFunction :: ToHaskellFunction a => String -> a -> Lua ()
@@ -66,7 +77,7 @@ addFunction name fn = do
6677 Lua. rawset (- 3 )
6778
6879-- | Lua callback function
69- newtype Callback = Callback { callbackStackIndex :: StackIndex }
80+ newtype Callback = Callback StackIndex
7081
7182instance Peekable Callback where
7283 peek idx = do
@@ -92,7 +103,7 @@ with_tmpdir :: String -- ^ parent dir or template
92103 -> AnyValue -- ^ template or callback
93104 -> Optional Callback -- ^ callback or nil
94105 -> Lua NumResults
95- with_tmpdir parentDir tmpl callback = do
106+ with_tmpdir parentDir tmpl callback =
96107 case fromOptional callback of
97108 Nothing -> do
98109 -- At most two args. The first arg (parent dir) has probably been
0 commit comments