Skip to content
This repository was archived by the owner on Mar 22, 2021. It is now read-only.

Commit ada11f4

Browse files
committed
Use module helpers available in HsLua 1.0.3
1 parent 8bb7724 commit ada11f4

4 files changed

Lines changed: 22 additions & 50 deletions

File tree

hslua-module-system.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ library
3131
, containers >= 0.5 && < 0.7
3232
, directory >= 1.3 && < 1.4
3333
, exceptions >= 0.8 && < 0.11
34-
, hslua >= 1.0 && < 1.2
34+
, hslua >= 1.0.3 && < 1.2
3535
, temporary >= 1.2 && < 1.4
3636
default-extensions: LambdaCase
3737
default-language: Haskell2010

src/Foreign/Lua/Module/System.hs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,28 @@ import qualified System.IO.Temp as Temp
5959
pushModule :: Lua NumResults
6060
pushModule = do
6161
Lua.newtable
62-
addField "arch" arch
63-
addField "compiler_name" compiler_name
64-
addField "compiler_version" compiler_version
65-
addField "os" os
66-
addFunction "env" env
67-
addFunction "getenv" getenv
68-
addFunction "getwd" getwd
69-
addFunction "ls" ls
70-
addFunction "mkdir" mkdir
71-
addFunction "rmdir" rmdir
72-
addFunction "setenv" setenv
73-
addFunction "setwd" setwd
74-
addFunction "tmpdirname" tmpdirname
75-
addFunction "with_env" with_env
76-
addFunction "with_tmpdir" with_tmpdir
77-
addFunction "with_wd" with_wd
62+
Lua.addfield "arch" arch
63+
Lua.addfield "compiler_name" compiler_name
64+
Lua.addfield "compiler_version" compiler_version
65+
Lua.addfield "os" os
66+
Lua.addfunction "env" env
67+
Lua.addfunction "getenv" getenv
68+
Lua.addfunction "getwd" getwd
69+
Lua.addfunction "ls" ls
70+
Lua.addfunction "mkdir" mkdir
71+
Lua.addfunction "rmdir" rmdir
72+
Lua.addfunction "setenv" setenv
73+
Lua.addfunction "setwd" setwd
74+
Lua.addfunction "tmpdirname" tmpdirname
75+
Lua.addfunction "with_env" with_env
76+
Lua.addfunction "with_tmpdir" with_tmpdir
77+
Lua.addfunction "with_wd" with_wd
7878
return 1
7979

8080
-- | Add the @system@ module under the given name to the table of
8181
-- preloaded packages.
8282
preloadModule :: String -> Lua ()
83-
preloadModule = flip addPackagePreloader pushModule
84-
83+
preloadModule = flip Lua.preloadhs pushModule
8584

8685
--
8786
-- Fields

src/Foreign/Lua/Module/SystemUtils.hs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,16 @@ Utility functions and types for HsLua's system module.
1111
module Foreign.Lua.Module.SystemUtils
1212
( AnyValue (..)
1313
, Callback (..)
14-
, addPackagePreloader
15-
, addField
16-
, addFunction
1714
, invoke
1815
, invokeWithFilePath
1916
, ioToLua
2017
)
2118
where
2219

2320
import Control.Exception (IOException, try)
24-
import Foreign.Lua (Lua, NumResults(..), Peekable, Pushable,
25-
StackIndex, ToHaskellFunction)
26-
21+
import Foreign.Lua (Lua, NumResults(..), Peekable, Pushable, StackIndex)
2722
import qualified Foreign.Lua as Lua
2823

29-
-- | Registers a preloading function. Takes an module name and the Lua
30-
-- operation which produces the package.
31-
addPackagePreloader :: String -> Lua NumResults -> Lua ()
32-
addPackagePreloader name modulePusher = do
33-
Lua.getfield Lua.registryindex Lua.preloadTableRegistryField
34-
Lua.pushHaskellFunction modulePusher
35-
Lua.setfield (-2) name
36-
Lua.pop 1
37-
38-
-- | Add a string-indexed field to the table at the top of the stack.
39-
addField :: Pushable a => String -> a -> Lua ()
40-
addField name value = do
41-
Lua.push name
42-
Lua.push value
43-
Lua.rawset (Lua.nthFromTop 3)
44-
45-
-- | Attach a function to the table at the top of the stack, using the
46-
-- given name.
47-
addFunction :: ToHaskellFunction a => String -> a -> Lua ()
48-
addFunction name fn = do
49-
Lua.push name
50-
Lua.pushHaskellFunction fn
51-
Lua.rawset (-3)
52-
5324
-- | Lua callback function
5425
newtype Callback = Callback StackIndex
5526

stack.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
resolver: lts-13.18
22
packages:
3-
- .
3+
- .
4+
extra-deps:
5+
- hslua-1.0.3

0 commit comments

Comments
 (0)