File: README.md

package info (click to toggle)
haskell-hslua-module-system 1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 92 kB
  • sloc: haskell: 430; makefile: 3
file content (312 lines) | stat: -rw-r--r-- 6,304 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
HsLua Module: System
====================

This module provides access to system information and functionality via
Haskell's `System` module.

Intended usage for this package is to preload it by adding the loader
function to `package.preload`. Note that the Lua `package` library must
have already been loaded before the loader can be added.

Example
-------

``` haskell
loadProg :: Lua Status
loadProg = do
  openlibs
  preloadModule documentedModule
  -- create a temporary directory, print it's path, then delete it again.
  dostring $ "system = require 'system'\n"
          <> "system.with_tmpdir('.', 'foo', print)"
```

Documentation
-------------

### Fields

#### arch

The machine architecture on which the program is running.

#### compiler_name

The Haskell implementation with which the host program was compiled.

#### compiler_version

The version of `compiler_name` with which the host program was compiled.

#### cputime_precision

The smallest measurable difference in CPU time that the
implementation can record, and is given as an integral number of
picoseconds.

#### os

The operating system on which the program is running.

### General Functions

#### cmd

`cmd (command, args[, input[, opts]])`

Executes a system command with the given arguments and `input` on
*stdin*.

Parameters:

`command`
:   command to execute (string)

`args`
:   command arguments ({string,...})

`input`
:   input on stdin (string)

`opts`
:   process options (table)

Returns:

- exit code – `false` on success, an integer otherwise
  (integer|boolean)

- stdout (string)

- stderr (string)


#### cputime

`cputime ()`

Returns the number of picoseconds CPU time used by the current
program. The precision of this result may vary in different
versions and on different platforms. See also the field
`cputime_precision`.

#### env

`env ()`

Retrieve the entire environment.

Returns:

- A table mapping environment variables names to their string value
  (table).

#### getenv

`getenv (var)`

Return the value of the environment variable `var`, or `nil` if there
is no such value.

Parameters:

`var`
:   name of the environment variable (string)

Returns:

- value of the variable, or nil if the variable is not defined (string
  or nil).

#### getwd

`getwd ()`

Obtain the current working directory as an absolute path.

Returns:

- The current working directory (string).

#### ls

`ls ([directory])`

List the contents of a directory.

Parameters:

`directory`
:   Path of the directory whose contents should be listed (string).
    Defaults to `.`.

Returns:

- A table of all entries in `directory` without the special entries (`.`
  and `..`).

#### mkdir

`mkdir (dirname [, create_parent])`

Create a new directory which is initially empty, or as near to
empty as the operating system allows. The function throws an
error if the directory cannot be created, e.g., if the parent
directory does not exist or if a directory of the same name is
already present.

If the optional second parameter is provided and truthy, then all
directories, including parent directories, are created as
necessary.

Parameters:

`dirname`
:   name of the new directory

`create_parent`
:   create parent directories if necessary

#### rmdir

`rmdir (dirname [, recursive])`

Remove an existing, empty directory. If `recursive` is given,
then delete the directory and its contents recursively.

Parameters:

`dirname`
:   name of the directory to delete

`recursive`
:   delete content recursively

#### setenv

`setenv (var, value)`

Set the specified environment variable to a new value.

Parameters:

`var`
:   name of the environment variable (string).

`value`
:   new value (string).

#### setwd

`setwd (directory)`

Change the working directory to the given path.

Parameters:

`directory`
:   Path of the directory which is to become the new working
    directory (string)

#### tmpdirname

`tmpdirname ()`

Returns the current directory for temporary files.

On Unix, `tmpdirname()` returns the value of the `TMPDIR` environment
variable or "/tmp" if the variable isn't defined. On Windows, the
function checks for the existence of environment variables in the
following order and uses the first path found:

- TMP environment variable.
- TEMP environment variable.
- USERPROFILE environment variable.
- The Windows directory

The operation may fail if the operating system has no notion of
temporary directory.

The function doesn't verify whether the path exists.

Returns:

- The current directory for temporary files (string).

#### with\_env

`with_env (environment, callback)`

Run an action within a custom environment. Only the environment
variables given by `environment` will be set, when `callback` is
called. The original environment is restored after this function
finishes, even if an error occurs while running the callback
action.

Parameters:

`environment`
:   Environment variables and their values to be set before
    running `callback`. (table with string keys and string
    values)

`callback`
:   Action to execute in the custom environment (function)

Returns:

- The result(s) of the call to `callback`

#### with\_tmpdir

`with_tmpdir ([parent_dir,] templ, callback)`

Create and use a temporary directory inside the given directory.
The directory is deleted after use.

Parameters:

`parent_dir`
:   Parent directory to create the directory in (string). If this
    parameter is omitted, the system's canonical temporary directory is
    used.

`templ`
:   Directory name template (string).

`callback`
:   Function which takes the name of the temporary directory as its
    first argument (function).

Returns:

- The result of the call to `callback`.

#### with\_wd

`with_wd (directory, callback)`

Run an action within a different directory. This function will
change the working directory to `directory`, execute `callback`,
then switch back to the original working directory, even if an
error occurs while running the callback action.

Parameters:

`directory`
:   Directory in which the given `callback` should be executed
    (string)

`callback`
:   Action to execute in the given directory (function)

Returns:

- The result(s) of the call to `callback`


License
-------

This package is licensed under the MIT license. See [`LICENSE`](LICENSE)
for details.