diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2023-11-15 19:28:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-15 19:28:06 +0100 |
commit | 90997893cc568c86805afa95db28439c28e32980 (patch) | |
tree | 4a692fcc91a811e18023ba1896aeee23fe2ee2c5 | |
parent | f868c16514be69b20a4e771cc347a80c9c439db6 (diff) | |
parent | 048f3cec7a18e7a28146f03c3c9e5d89d9613028 (diff) | |
download | luasystem-90997893cc568c86805afa95db28439c28e32980.tar.gz luasystem-90997893cc568c86805afa95db28439c28e32980.tar.bz2 luasystem-90997893cc568c86805afa95db28439c28e32980.zip |
Merge pull request #6 from lunarmodules/time
-rw-r--r-- | CHANGELOG.md | 48 | ||||
-rw-r--r-- | LICENSE.md (renamed from LICENSE) | 29 | ||||
-rw-r--r-- | README.md | 29 | ||||
-rw-r--r-- | appveyor.yml | 2 | ||||
-rw-r--r-- | config.ld | 16 | ||||
-rw-r--r-- | doc_topics/01-introduction.md | 12 | ||||
-rw-r--r-- | doc_topics/ldoc.css | 291 | ||||
-rw-r--r-- | docs/index.html | 366 | ||||
-rw-r--r-- | docs/ldoc.css | 291 | ||||
-rw-r--r-- | docs/topics/01-introduction.md.html | 70 | ||||
-rw-r--r-- | docs/topics/CHANGELOG.md.html | 121 | ||||
-rw-r--r-- | docs/topics/LICENSE.md.html | 79 | ||||
-rw-r--r-- | luasystem-scm-0.rockspec | 13 | ||||
-rw-r--r-- | rockspecs/luasystem-0.2.1-1.rockspec | 2 | ||||
-rw-r--r-- | spec/01-time_spec.lua | 76 | ||||
-rw-r--r-- | spec/02-random_spec.lua | 47 | ||||
-rw-r--r-- | spec/03-environment_spec.lua | 81 | ||||
-rw-r--r-- | spec/time_spec.lua | 31 | ||||
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/compat.h | 27 | ||||
-rw-r--r-- | src/core.c | 16 | ||||
-rw-r--r-- | src/environment.c | 173 | ||||
-rw-r--r-- | src/random.c | 117 | ||||
-rw-r--r-- | src/term.c | 37 | ||||
-rw-r--r-- | src/time.c | 87 |
25 files changed, 1970 insertions, 95 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..56d1886 --- /dev/null +++ b/CHANGELOG.md | |||
@@ -0,0 +1,48 @@ | |||
1 | # CHANGELOG | ||
2 | |||
3 | ## Versioning | ||
4 | |||
5 | This library is versioned based on Semantic Versioning ([SemVer](https://semver.org/)). | ||
6 | |||
7 | #### Version scoping | ||
8 | |||
9 | The scope of what is covered by the version number excludes: | ||
10 | |||
11 | - error messages; the text of the messages can change, unless specifically documented. | ||
12 | |||
13 | #### Releasing new versions | ||
14 | |||
15 | - create a release branch | ||
16 | - update the changelog below | ||
17 | - update version and copyright-years in `./LICENSE.md` and `./src/time.c` (in module constants) | ||
18 | - create a new rockspec and update the version inside the new rockspec:<br/> | ||
19 | `cp luasystem-scm-0.rockspec ./rockspecs/luasystem-X.Y.Z-1.rockspec` | ||
20 | - clean and render the docs: run `ldoc .` | ||
21 | - commit the changes as `Release vX.Y.Z` | ||
22 | - push the commit, and create a release PR | ||
23 | - after merging tag the release commit with `vX.Y.Z` | ||
24 | - upload to LuaRocks:<br/> | ||
25 | `luarocks upload ./rockspecs/luasystem-X.Y.Z-1.rockspec --api-key=ABCDEFGH` | ||
26 | - test the newly created rock:<br/> | ||
27 | `luarocks install luasystem` | ||
28 | |||
29 | ## Version history | ||
30 | |||
31 | ### Version X.Y.Z, unreleased | ||
32 | |||
33 | - Feat: on Windows `sleep` now has a precision parameter | ||
34 | - Feat: `setenv` added to set environment variables. | ||
35 | - Feat: `getenvs` added to list environment variables. | ||
36 | - Feat: `getenv` added to get environment variable previously set (Windows). | ||
37 | - Feat: `random` added to return high-quality random bytes | ||
38 | - Feat: `isatty` added to check if a file-handle is a tty | ||
39 | |||
40 | ### Version 0.2.1, released 02-Oct-2016 | ||
41 | |||
42 | ### Version 0.2.0, released 08-May-2016 | ||
43 | |||
44 | ### Version 0.1.1, released 10-Apr-2016 | ||
45 | |||
46 | ### Version 0.1.0, released 11-Feb-2016 | ||
47 | |||
48 | - initial release | ||
@@ -1,20 +1,21 @@ | |||
1 | MIT License Terms | 1 | # MIT License |
2 | ================= | ||
3 | 2 | ||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of | 3 | ### Copyright (c) 2016-2023 Oscar Lim |
5 | this software and associated documentation files (the "Software"), to deal in | 4 | |
6 | the Software without restriction, including without limitation the rights to | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | 6 | this software and associated documentation files (the "Software"), to deal in |
8 | of the Software, and to permit persons to whom the Software is furnished to do | 7 | the Software without restriction, including without limitation the rights to |
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
9 | of the Software, and to permit persons to whom the Software is furnished to do | ||
9 | so, subject to the following conditions: | 10 | so, subject to the following conditions: |
10 | 11 | ||
11 | The above copyright notice and this permission notice shall be included in all | 12 | The above copyright notice and this permission notice shall be included in all |
12 | copies or substantial portions of the Software. | 13 | copies or substantial portions of the Software. |
13 | 14 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
20 | SOFTWARE. | 21 | SOFTWARE. |
@@ -1,20 +1,21 @@ | |||
1 | LuaSystem | 1 | [](https://github.com/lunarmodules/luasystem/actions/workflows/unix_build.yml) |
2 | ====== | 2 | [](https://ci.appveyor.com/project/Tieske/luasystem/branch/master) |
3 | 3 | [](https://github.com/lunarmodules/luasystem/actions/workflows/lint.yml) | |
4 | [](https://travis-ci.org/o-lim/luasystem/builds) | 4 | [](CHANGELOG.md) |
5 | 5 | ||
6 | # LuaSystem | ||
6 | 7 | ||
7 | luasystem is a platform independent system call library for Lua. | 8 | luasystem is a platform independent system call library for Lua. |
8 | Supports Lua >= 5.1 and luajit >= 2.0.0. | 9 | Supports Unix, Windows, MacOS, `Lua >= 5.1` and `luajit >= 2.0.0`. |
10 | |||
11 | ## License and copyright | ||
12 | |||
13 | See [LICENSE.md](LICENSE.md) | ||
14 | |||
15 | ## Documentation | ||
9 | 16 | ||
10 | Currently the following functions are supported: | 17 | See [online documentation](https://lunarmodules.github.io/luasystem/) |
11 | * gettime | ||
12 | * monotime | ||
13 | * sleep | ||
14 | 18 | ||
15 | License | 19 | ## Changelog & Versioning |
16 | ------- | ||
17 | 20 | ||
18 | This code and its accompanying README are | 21 | See [CHANGELOG.md](CHANGELOG.md) |
19 | [MIT licensed](http://www.opensource.org/licenses/mit-license.php). | ||
20 | See LICENSE for details. | ||
diff --git a/appveyor.yml b/appveyor.yml index 596c846..f39445b 100644 --- a/appveyor.yml +++ b/appveyor.yml | |||
@@ -26,4 +26,4 @@ build_script: | |||
26 | - luarocks make | 26 | - luarocks make |
27 | 27 | ||
28 | test_script: | 28 | test_script: |
29 | - busted | 29 | - busted --Xoutput "--color" |
diff --git a/config.ld b/config.ld new file mode 100644 index 0000000..c13936d --- /dev/null +++ b/config.ld | |||
@@ -0,0 +1,16 @@ | |||
1 | project='Lua-System' | ||
2 | title='Lua-System docs' | ||
3 | description='Platform independent system calls for Lua' | ||
4 | |||
5 | format='markdown' | ||
6 | use_markdown_titles = true | ||
7 | style="./doc_topics/" | ||
8 | |||
9 | file={'./src/', './system/'} | ||
10 | topics={'./doc_topics/', './LICENSE.md', './CHANGELOG.md'} | ||
11 | -- examples = {'./examples'} | ||
12 | |||
13 | dir='docs' | ||
14 | sort=true | ||
15 | sort_modules=true | ||
16 | all=false | ||
diff --git a/doc_topics/01-introduction.md b/doc_topics/01-introduction.md new file mode 100644 index 0000000..9cc2347 --- /dev/null +++ b/doc_topics/01-introduction.md | |||
@@ -0,0 +1,12 @@ | |||
1 | # 1. Introduction | ||
2 | |||
3 | luasystem is a platform independent system call library for Lua. | ||
4 | Supports Unix, Windows, MacOS, `Lua >= 5.1` and `luajit >= 2.0.0`. | ||
5 | |||
6 | Lua is typically platform independent, but it requires adhering to very old C | ||
7 | standards. This in turn means that many common features (according to todays standards) | ||
8 | are not available. This module attempts to overcome some of those hurdles by providing | ||
9 | functions that cover those common needs. | ||
10 | |||
11 | This is not a kitchen sink library, but a minimalistic one with a focus on platform | ||
12 | independence. | ||
diff --git a/doc_topics/ldoc.css b/doc_topics/ldoc.css new file mode 100644 index 0000000..5b9fbbf --- /dev/null +++ b/doc_topics/ldoc.css | |||
@@ -0,0 +1,291 @@ | |||
1 | body { | ||
2 | color: #47555c; | ||
3 | font-size: 16px; | ||
4 | font-family: "Open Sans", sans-serif; | ||
5 | margin: 0; | ||
6 | background: #eff4ff; | ||
7 | } | ||
8 | |||
9 | a:link { color: #008fee; } | ||
10 | a:visited { color: #008fee; } | ||
11 | a:hover { color: #22a7ff; } | ||
12 | |||
13 | h1 { font-size:26px; font-weight: normal; } | ||
14 | h2 { font-size:22px; font-weight: normal; } | ||
15 | h3 { font-size:18px; font-weight: normal; } | ||
16 | h4 { font-size:16px; font-weight: bold; } | ||
17 | |||
18 | hr { | ||
19 | height: 1px; | ||
20 | background: #c1cce4; | ||
21 | border: 0px; | ||
22 | margin: 15px 0; | ||
23 | } | ||
24 | |||
25 | code, tt { | ||
26 | font-family: monospace; | ||
27 | } | ||
28 | span.parameter { | ||
29 | font-family: monospace; | ||
30 | font-weight: bold; | ||
31 | color: rgb(99, 115, 131); | ||
32 | } | ||
33 | span.parameter:after { | ||
34 | content:":"; | ||
35 | } | ||
36 | span.types:before { | ||
37 | content:"("; | ||
38 | } | ||
39 | span.types:after { | ||
40 | content:")"; | ||
41 | } | ||
42 | .type { | ||
43 | font-weight: bold; font-style:italic | ||
44 | } | ||
45 | |||
46 | p.name { | ||
47 | font-family: "Andale Mono", monospace; | ||
48 | } | ||
49 | |||
50 | #navigation { | ||
51 | float: left; | ||
52 | background-color: white; | ||
53 | border-right: 1px solid #d3dbec; | ||
54 | border-bottom: 1px solid #d3dbec; | ||
55 | |||
56 | width: 14em; | ||
57 | vertical-align: top; | ||
58 | overflow: visible; | ||
59 | } | ||
60 | |||
61 | #navigation br { | ||
62 | display: none; | ||
63 | } | ||
64 | |||
65 | #navigation h1 { | ||
66 | background-color: white; | ||
67 | border-bottom: 1px solid #d3dbec; | ||
68 | padding: 15px; | ||
69 | margin-top: 0px; | ||
70 | margin-bottom: 0px; | ||
71 | } | ||
72 | |||
73 | #navigation h2 { | ||
74 | font-size: 18px; | ||
75 | background-color: white; | ||
76 | border-bottom: 1px solid #d3dbec; | ||
77 | padding-left: 15px; | ||
78 | padding-right: 15px; | ||
79 | padding-top: 10px; | ||
80 | padding-bottom: 10px; | ||
81 | margin-top: 30px; | ||
82 | margin-bottom: 0px; | ||
83 | } | ||
84 | |||
85 | #content h1 { | ||
86 | background-color: #2c3e67; | ||
87 | color: white; | ||
88 | padding: 15px; | ||
89 | margin: 0px; | ||
90 | } | ||
91 | |||
92 | #content h2 { | ||
93 | background-color: #6c7ea7; | ||
94 | color: white; | ||
95 | padding: 15px; | ||
96 | padding-top: 15px; | ||
97 | padding-bottom: 15px; | ||
98 | margin-top: 0px; | ||
99 | } | ||
100 | |||
101 | #content h2 a { | ||
102 | background-color: #6c7ea7; | ||
103 | color: white; | ||
104 | text-decoration: none; | ||
105 | } | ||
106 | |||
107 | #content h2 a:hover { | ||
108 | text-decoration: underline; | ||
109 | } | ||
110 | |||
111 | #content h3 { | ||
112 | font-style: italic; | ||
113 | padding-top: 15px; | ||
114 | padding-bottom: 4px; | ||
115 | margin-right: 15px; | ||
116 | margin-left: 15px; | ||
117 | margin-bottom: 5px; | ||
118 | border-bottom: solid 1px #bcd; | ||
119 | } | ||
120 | |||
121 | #content h4 { | ||
122 | margin-right: 15px; | ||
123 | margin-left: 15px; | ||
124 | border-bottom: solid 1px #bcd; | ||
125 | } | ||
126 | |||
127 | #content pre { | ||
128 | margin: 15px; | ||
129 | } | ||
130 | |||
131 | pre { | ||
132 | background-color: rgb(50, 55, 68); | ||
133 | color: white; | ||
134 | border-radius: 3px; | ||
135 | /* border: 1px solid #C0C0C0; /* silver */ | ||
136 | padding: 15px; | ||
137 | overflow: auto; | ||
138 | font-family: "Andale Mono", monospace; | ||
139 | } | ||
140 | |||
141 | #content ul pre.example { | ||
142 | margin-left: 0px; | ||
143 | } | ||
144 | |||
145 | table.index { | ||
146 | /* border: 1px #00007f; */ | ||
147 | } | ||
148 | table.index td { text-align: left; vertical-align: top; } | ||
149 | |||
150 | #navigation ul | ||
151 | { | ||
152 | font-size:1em; | ||
153 | list-style-type: none; | ||
154 | margin: 1px 1px 10px 1px; | ||
155 | padding-left: 20px; | ||
156 | } | ||
157 | |||
158 | #navigation li { | ||
159 | text-indent: -1em; | ||
160 | display: block; | ||
161 | margin: 3px 0px 0px 22px; | ||
162 | } | ||
163 | |||
164 | #navigation li li a { | ||
165 | margin: 0px 3px 0px -1em; | ||
166 | } | ||
167 | |||
168 | #content { | ||
169 | margin-left: 14em; | ||
170 | } | ||
171 | |||
172 | #content p { | ||
173 | padding-left: 15px; | ||
174 | padding-right: 15px; | ||
175 | } | ||
176 | |||
177 | #content table { | ||
178 | padding-left: 15px; | ||
179 | padding-right: 15px; | ||
180 | background-color: white; | ||
181 | } | ||
182 | |||
183 | #content p, #content table, #content ol, #content ul, #content dl { | ||
184 | max-width: 900px; | ||
185 | } | ||
186 | |||
187 | #about { | ||
188 | padding: 15px; | ||
189 | padding-left: 16em; | ||
190 | background-color: white; | ||
191 | border-top: 1px solid #d3dbec; | ||
192 | border-bottom: 1px solid #d3dbec; | ||
193 | } | ||
194 | |||
195 | table.module_list, table.function_list { | ||
196 | border-width: 1px; | ||
197 | border-style: solid; | ||
198 | border-color: #cccccc; | ||
199 | border-collapse: collapse; | ||
200 | margin: 15px; | ||
201 | } | ||
202 | table.module_list td, table.function_list td { | ||
203 | border-width: 1px; | ||
204 | padding-left: 10px; | ||
205 | padding-right: 10px; | ||
206 | padding-top: 5px; | ||
207 | padding-bottom: 5px; | ||
208 | border: solid 1px rgb(193, 204, 228); | ||
209 | } | ||
210 | table.module_list td.name, table.function_list td.name { | ||
211 | background-color: white; min-width: 200px; border-right-width: 0px; | ||
212 | } | ||
213 | table.module_list td.summary, table.function_list td.summary { | ||
214 | background-color: white; width: 100%; border-left-width: 0px; | ||
215 | } | ||
216 | |||
217 | dl.function { | ||
218 | margin-right: 15px; | ||
219 | margin-left: 15px; | ||
220 | border-bottom: solid 1px rgb(193, 204, 228); | ||
221 | border-left: solid 1px rgb(193, 204, 228); | ||
222 | border-right: solid 1px rgb(193, 204, 228); | ||
223 | background-color: white; | ||
224 | } | ||
225 | |||
226 | dl.function dt { | ||
227 | color: rgb(99, 123, 188); | ||
228 | font-family: monospace; | ||
229 | border-top: solid 1px rgb(193, 204, 228); | ||
230 | padding: 15px; | ||
231 | } | ||
232 | |||
233 | dl.function dd { | ||
234 | margin-left: 15px; | ||
235 | margin-right: 15px; | ||
236 | margin-top: 5px; | ||
237 | margin-bottom: 15px; | ||
238 | } | ||
239 | |||
240 | #content dl.function dd h3 { | ||
241 | margin-top: 0px; | ||
242 | margin-left: 0px; | ||
243 | padding-left: 0px; | ||
244 | font-size: 16px; | ||
245 | color: rgb(128, 128, 128); | ||
246 | border-bottom: solid 1px #def; | ||
247 | } | ||
248 | |||
249 | #content dl.function dd ul, #content dl.function dd ol { | ||
250 | padding: 0px; | ||
251 | padding-left: 15px; | ||
252 | list-style-type: none; | ||
253 | } | ||
254 | |||
255 | ul.nowrap { | ||
256 | overflow:auto; | ||
257 | white-space:nowrap; | ||
258 | } | ||
259 | |||
260 | .section-description { | ||
261 | padding-left: 15px; | ||
262 | padding-right: 15px; | ||
263 | } | ||
264 | |||
265 | /* stop sublists from having initial vertical space */ | ||
266 | ul ul { margin-top: 0px; } | ||
267 | ol ul { margin-top: 0px; } | ||
268 | ol ol { margin-top: 0px; } | ||
269 | ul ol { margin-top: 0px; } | ||
270 | |||
271 | /* make the target distinct; helps when we're navigating to a function */ | ||
272 | a:target + * { | ||
273 | background-color: #FF9; | ||
274 | } | ||
275 | |||
276 | |||
277 | /* styles for prettification of source */ | ||
278 | pre .comment { color: #bbccaa; } | ||
279 | pre .constant { color: #a8660d; } | ||
280 | pre .escape { color: #844631; } | ||
281 | pre .keyword { color: #ffc090; font-weight: bold; } | ||
282 | pre .library { color: #0e7c6b; } | ||
283 | pre .marker { color: #512b1e; background: #fedc56; font-weight: bold; } | ||
284 | pre .string { color: #8080ff; } | ||
285 | pre .number { color: #f8660d; } | ||
286 | pre .operator { color: #2239a8; font-weight: bold; } | ||
287 | pre .preprocessor, pre .prepro { color: #a33243; } | ||
288 | pre .global { color: #c040c0; } | ||
289 | pre .user-keyword { color: #800080; } | ||
290 | pre .prompt { color: #558817; } | ||
291 | pre .url { color: #272fc2; text-decoration: underline; } | ||
diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..eb241c6 --- /dev/null +++ b/docs/index.html | |||
@@ -0,0 +1,366 @@ | |||
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
3 | <html> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
5 | <head> | ||
6 | <title>Lua-System docs</title> | ||
7 | <link rel="stylesheet" href="ldoc.css" type="text/css" /> | ||
8 | </head> | ||
9 | <body> | ||
10 | |||
11 | <div id="container"> | ||
12 | |||
13 | <div id="product"> | ||
14 | <div id="product_logo"></div> | ||
15 | <div id="product_name"><big><b></b></big></div> | ||
16 | <div id="product_description"></div> | ||
17 | </div> <!-- id="product" --> | ||
18 | |||
19 | |||
20 | <div id="main"> | ||
21 | |||
22 | |||
23 | <!-- Menu --> | ||
24 | |||
25 | <div id="navigation"> | ||
26 | <br/> | ||
27 | <h1>Lua-System</h1> | ||
28 | |||
29 | |||
30 | <h2>Contents</h2> | ||
31 | <ul> | ||
32 | <li><a href="#environment_Functions">environment Functions</a></li> | ||
33 | <li><a href="#random_Functions">random Functions</a></li> | ||
34 | <li><a href="#term_Functions">term Functions</a></li> | ||
35 | <li><a href="#time_Functions">time Functions</a></li> | ||
36 | </ul> | ||
37 | |||
38 | |||
39 | <h2>Modules</h2> | ||
40 | <ul class="nowrap"> | ||
41 | <li><strong>system</strong></li> | ||
42 | </ul> | ||
43 | <h2>Topics</h2> | ||
44 | <ul class=""> | ||
45 | <li><a href="topics/01-introduction.md.html">1. Introduction</a></li> | ||
46 | <li><a href="topics/CHANGELOG.md.html">CHANGELOG</a></li> | ||
47 | <li><a href="topics/LICENSE.md.html">MIT License</a></li> | ||
48 | </ul> | ||
49 | |||
50 | </div> | ||
51 | |||
52 | <div id="content"> | ||
53 | |||
54 | <h1>Module <code>system</code></h1> | ||
55 | <p>Platform independent system calls for Lua.</p> | ||
56 | <p> | ||
57 | |||
58 | </p> | ||
59 | |||
60 | |||
61 | <h2><a href="#environment_Functions">environment Functions</a></h2> | ||
62 | <table class="function_list"> | ||
63 | <tr> | ||
64 | <td class="name" nowrap><a href="#getenv">getenv (name)</a></td> | ||
65 | <td class="summary">Gets the value of an environment variable.</td> | ||
66 | </tr> | ||
67 | <tr> | ||
68 | <td class="name" nowrap><a href="#getenvs">getenvs ()</a></td> | ||
69 | <td class="summary">Returns a table with all environment variables.</td> | ||
70 | </tr> | ||
71 | <tr> | ||
72 | <td class="name" nowrap><a href="#setenv">setenv (name[, value])</a></td> | ||
73 | <td class="summary">Sets an environment variable.</td> | ||
74 | </tr> | ||
75 | </table> | ||
76 | <h2><a href="#random_Functions">random Functions</a></h2> | ||
77 | <table class="function_list"> | ||
78 | <tr> | ||
79 | <td class="name" nowrap><a href="#random">random ([length=1])</a></td> | ||
80 | <td class="summary">Generate random bytes.</td> | ||
81 | </tr> | ||
82 | </table> | ||
83 | <h2><a href="#term_Functions">term Functions</a></h2> | ||
84 | <table class="function_list"> | ||
85 | <tr> | ||
86 | <td class="name" nowrap><a href="#isatty">isatty (file)</a></td> | ||
87 | <td class="summary">Checks if a file-handle is a TTY.</td> | ||
88 | </tr> | ||
89 | </table> | ||
90 | <h2><a href="#time_Functions">time Functions</a></h2> | ||
91 | <table class="function_list"> | ||
92 | <tr> | ||
93 | <td class="name" nowrap><a href="#gettime">gettime ()</a></td> | ||
94 | <td class="summary">Get system time.</td> | ||
95 | </tr> | ||
96 | <tr> | ||
97 | <td class="name" nowrap><a href="#monotime">monotime ()</a></td> | ||
98 | <td class="summary">Get monotonic time.</td> | ||
99 | </tr> | ||
100 | <tr> | ||
101 | <td class="name" nowrap><a href="#sleep">sleep (seconds[, precision=16])</a></td> | ||
102 | <td class="summary">Sleep without a busy loop.</td> | ||
103 | </tr> | ||
104 | </table> | ||
105 | |||
106 | <br/> | ||
107 | <br/> | ||
108 | |||
109 | |||
110 | <h2 class="section-header "><a name="environment_Functions"></a>environment Functions</h2> | ||
111 | |||
112 | <dl class="function"> | ||
113 | <dt> | ||
114 | <a name = "getenv"></a> | ||
115 | <strong>getenv (name)</strong> | ||
116 | </dt> | ||
117 | <dd> | ||
118 | Gets the value of an environment variable. </p> | ||
119 | |||
120 | <p><strong>NOTE</strong>: Windows has multiple copies of environment variables. For this reason, | ||
121 | the <a href="index.html#setenv">setenv</a> function will not work with Lua's <a href="https://www.lua.org/manual/5.1/manual.html#pdf-os.getenv">os.getenv</a> on Windows. If you want | ||
122 | to use <a href="index.html#setenv">setenv</a> then consider patching <a href="https://www.lua.org/manual/5.1/manual.html#pdf-os.getenv">os.getenv</a> with this implementation of <a href="index.html#getenv">getenv</a>. | ||
123 | |||
124 | |||
125 | <h3>Parameters:</h3> | ||
126 | <ul> | ||
127 | <li><span class="parameter">name</span> | ||
128 | <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span> | ||
129 | name of the environment variable | ||
130 | </li> | ||
131 | </ul> | ||
132 | |||
133 | <h3>Returns:</h3> | ||
134 | <ol> | ||
135 | |||
136 | <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span> | ||
137 | value of the environment variable, or nil if the variable is not set | ||
138 | </ol> | ||
139 | |||
140 | |||
141 | |||
142 | |||
143 | </dd> | ||
144 | <dt> | ||
145 | <a name = "getenvs"></a> | ||
146 | <strong>getenvs ()</strong> | ||
147 | </dt> | ||
148 | <dd> | ||
149 | Returns a table with all environment variables. | ||
150 | |||
151 | |||
152 | |||
153 | <h3>Returns:</h3> | ||
154 | <ol> | ||
155 | |||
156 | <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span> | ||
157 | table with all environment variables and their values | ||
158 | </ol> | ||
159 | |||
160 | |||
161 | |||
162 | |||
163 | </dd> | ||
164 | <dt> | ||
165 | <a name = "setenv"></a> | ||
166 | <strong>setenv (name[, value])</strong> | ||
167 | </dt> | ||
168 | <dd> | ||
169 | Sets an environment variable. </p> | ||
170 | |||
171 | <p><strong>NOTE</strong>: Windows has multiple copies of environment variables. For this reason, the | ||
172 | <a href="index.html#setenv">setenv</a> function will not work with Lua's <a href="https://www.lua.org/manual/5.1/manual.html#pdf-os.getenv">os.getenv</a> on Windows. If you want to use | ||
173 | it then consider patching <a href="https://www.lua.org/manual/5.1/manual.html#pdf-os.getenv">os.getenv</a> with the implementation of <a href="index.html#getenv">system.getenv</a>. | ||
174 | |||
175 | |||
176 | <h3>Parameters:</h3> | ||
177 | <ul> | ||
178 | <li><span class="parameter">name</span> | ||
179 | <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span> | ||
180 | name of the environment variable | ||
181 | </li> | ||
182 | <li><span class="parameter">value</span> | ||
183 | <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span> | ||
184 | value of the environment variable, if <code>nil</code> the variable will be deleted (on | ||
185 | Windows, setting an empty string, will also delete the variable) | ||
186 | (<em>optional</em>) | ||
187 | </li> | ||
188 | </ul> | ||
189 | |||
190 | <h3>Returns:</h3> | ||
191 | <ol> | ||
192 | |||
193 | <span class="types"><span class="type">boolean</span></span> | ||
194 | success | ||
195 | </ol> | ||
196 | |||
197 | |||
198 | |||
199 | |||
200 | </dd> | ||
201 | </dl> | ||
202 | <h2 class="section-header "><a name="random_Functions"></a>random Functions</h2> | ||
203 | |||
204 | <dl class="function"> | ||
205 | <dt> | ||
206 | <a name = "random"></a> | ||
207 | <strong>random ([length=1])</strong> | ||
208 | </dt> | ||
209 | <dd> | ||
210 | Generate random bytes. | ||
211 | This uses <code>CryptGenRandom()</code> on Windows, and <code>/dev/urandom</code> on other platforms. It will return the | ||
212 | requested number of bytes, or an error, never a partial result. | ||
213 | |||
214 | |||
215 | <h3>Parameters:</h3> | ||
216 | <ul> | ||
217 | <li><span class="parameter">length</span> | ||
218 | <span class="types"><span class="type">int</span></span> | ||
219 | number of bytes to get | ||
220 | (<em>default</em> 1) | ||
221 | </li> | ||
222 | </ul> | ||
223 | |||
224 | <h3>Returns:</h3> | ||
225 | <ol> | ||
226 | |||
227 | <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span> | ||
228 | string of random bytes | ||
229 | </ol> | ||
230 | <h3>Or</h3> | ||
231 | <ol> | ||
232 | <li> | ||
233 | <span class="types"><span class="type">nil</span></span> | ||
234 | |||
235 | |||
236 | </li> | ||
237 | <li> | ||
238 | <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span> | ||
239 | error message</li> | ||
240 | </ol> | ||
241 | |||
242 | |||
243 | |||
244 | |||
245 | </dd> | ||
246 | </dl> | ||
247 | <h2 class="section-header "><a name="term_Functions"></a>term Functions</h2> | ||
248 | |||
249 | <dl class="function"> | ||
250 | <dt> | ||
251 | <a name = "isatty"></a> | ||
252 | <strong>isatty (file)</strong> | ||
253 | </dt> | ||
254 | <dd> | ||
255 | Checks if a file-handle is a TTY. | ||
256 | |||
257 | |||
258 | <h3>Parameters:</h3> | ||
259 | <ul> | ||
260 | <li><span class="parameter">file</span> | ||
261 | <span class="types"><span class="type">file</span></span> | ||
262 | the file-handle to check | ||
263 | </li> | ||
264 | </ul> | ||
265 | |||
266 | <h3>Returns:</h3> | ||
267 | <ol> | ||
268 | |||
269 | <span class="types"><span class="type">boolean</span></span> | ||
270 | true if the file is a tty | ||
271 | </ol> | ||
272 | |||
273 | |||
274 | |||
275 | |||
276 | </dd> | ||
277 | </dl> | ||
278 | <h2 class="section-header "><a name="time_Functions"></a>time Functions</h2> | ||
279 | |||
280 | <dl class="function"> | ||
281 | <dt> | ||
282 | <a name = "gettime"></a> | ||
283 | <strong>gettime ()</strong> | ||
284 | </dt> | ||
285 | <dd> | ||
286 | Get system time. | ||
287 | The time is returned as the seconds since the epoch (1 January 1970 00:00:00). | ||
288 | |||
289 | |||
290 | |||
291 | <h3>Returns:</h3> | ||
292 | <ol> | ||
293 | |||
294 | <span class="types"><span class="type">number</span></span> | ||
295 | seconds (fractional) | ||
296 | </ol> | ||
297 | |||
298 | |||
299 | |||
300 | |||
301 | </dd> | ||
302 | <dt> | ||
303 | <a name = "monotime"></a> | ||
304 | <strong>monotime ()</strong> | ||
305 | </dt> | ||
306 | <dd> | ||
307 | Get monotonic time. | ||
308 | The time is returned as the seconds since system start. | ||
309 | |||
310 | |||
311 | |||
312 | <h3>Returns:</h3> | ||
313 | <ol> | ||
314 | |||
315 | <span class="types"><span class="type">number</span></span> | ||
316 | seconds (fractional) | ||
317 | </ol> | ||
318 | |||
319 | |||
320 | |||
321 | |||
322 | </dd> | ||
323 | <dt> | ||
324 | <a name = "sleep"></a> | ||
325 | <strong>sleep (seconds[, precision=16])</strong> | ||
326 | </dt> | ||
327 | <dd> | ||
328 | Sleep without a busy loop. | ||
329 | This function will sleep, without doing a busy-loop and wasting CPU cycles. | ||
330 | |||
331 | |||
332 | <h3>Parameters:</h3> | ||
333 | <ul> | ||
334 | <li><span class="parameter">seconds</span> | ||
335 | <span class="types"><span class="type">number</span></span> | ||
336 | seconds to sleep (fractional). | ||
337 | </li> | ||
338 | <li><span class="parameter">precision</span> | ||
339 | <span class="types"><span class="type">integer</span></span> | ||
340 | minimum stepsize in milliseconds (Windows only, ignored elsewhere) | ||
341 | (<em>default</em> 16) | ||
342 | </li> | ||
343 | </ul> | ||
344 | |||
345 | <h3>Returns:</h3> | ||
346 | <ol> | ||
347 | |||
348 | <code>true</code> on success, or <code>nil+err</code> on failure | ||
349 | </ol> | ||
350 | |||
351 | |||
352 | |||
353 | |||
354 | </dd> | ||
355 | </dl> | ||
356 | |||
357 | |||
358 | </div> <!-- id="content" --> | ||
359 | </div> <!-- id="main" --> | ||
360 | <div id="about"> | ||
361 | <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> | ||
362 | <i style="float:right;">Last updated 2023-11-15 07:42:18 </i> | ||
363 | </div> <!-- id="about" --> | ||
364 | </div> <!-- id="container" --> | ||
365 | </body> | ||
366 | </html> | ||
diff --git a/docs/ldoc.css b/docs/ldoc.css new file mode 100644 index 0000000..5b9fbbf --- /dev/null +++ b/docs/ldoc.css | |||
@@ -0,0 +1,291 @@ | |||
1 | body { | ||
2 | color: #47555c; | ||
3 | font-size: 16px; | ||
4 | font-family: "Open Sans", sans-serif; | ||
5 | margin: 0; | ||
6 | background: #eff4ff; | ||
7 | } | ||
8 | |||
9 | a:link { color: #008fee; } | ||
10 | a:visited { color: #008fee; } | ||
11 | a:hover { color: #22a7ff; } | ||
12 | |||
13 | h1 { font-size:26px; font-weight: normal; } | ||
14 | h2 { font-size:22px; font-weight: normal; } | ||
15 | h3 { font-size:18px; font-weight: normal; } | ||
16 | h4 { font-size:16px; font-weight: bold; } | ||
17 | |||
18 | hr { | ||
19 | height: 1px; | ||
20 | background: #c1cce4; | ||
21 | border: 0px; | ||
22 | margin: 15px 0; | ||
23 | } | ||
24 | |||
25 | code, tt { | ||
26 | font-family: monospace; | ||
27 | } | ||
28 | span.parameter { | ||
29 | font-family: monospace; | ||
30 | font-weight: bold; | ||
31 | color: rgb(99, 115, 131); | ||
32 | } | ||
33 | span.parameter:after { | ||
34 | content:":"; | ||
35 | } | ||
36 | span.types:before { | ||
37 | content:"("; | ||
38 | } | ||
39 | span.types:after { | ||
40 | content:")"; | ||
41 | } | ||
42 | .type { | ||
43 | font-weight: bold; font-style:italic | ||
44 | } | ||
45 | |||
46 | p.name { | ||
47 | font-family: "Andale Mono", monospace; | ||
48 | } | ||
49 | |||
50 | #navigation { | ||
51 | float: left; | ||
52 | background-color: white; | ||
53 | border-right: 1px solid #d3dbec; | ||
54 | border-bottom: 1px solid #d3dbec; | ||
55 | |||
56 | width: 14em; | ||
57 | vertical-align: top; | ||
58 | overflow: visible; | ||
59 | } | ||
60 | |||
61 | #navigation br { | ||
62 | display: none; | ||
63 | } | ||
64 | |||
65 | #navigation h1 { | ||
66 | background-color: white; | ||
67 | border-bottom: 1px solid #d3dbec; | ||
68 | padding: 15px; | ||
69 | margin-top: 0px; | ||
70 | margin-bottom: 0px; | ||
71 | } | ||
72 | |||
73 | #navigation h2 { | ||
74 | font-size: 18px; | ||
75 | background-color: white; | ||
76 | border-bottom: 1px solid #d3dbec; | ||
77 | padding-left: 15px; | ||
78 | padding-right: 15px; | ||
79 | padding-top: 10px; | ||
80 | padding-bottom: 10px; | ||
81 | margin-top: 30px; | ||
82 | margin-bottom: 0px; | ||
83 | } | ||
84 | |||
85 | #content h1 { | ||
86 | background-color: #2c3e67; | ||
87 | color: white; | ||
88 | padding: 15px; | ||
89 | margin: 0px; | ||
90 | } | ||
91 | |||
92 | #content h2 { | ||
93 | background-color: #6c7ea7; | ||
94 | color: white; | ||
95 | padding: 15px; | ||
96 | padding-top: 15px; | ||
97 | padding-bottom: 15px; | ||
98 | margin-top: 0px; | ||
99 | } | ||
100 | |||
101 | #content h2 a { | ||
102 | background-color: #6c7ea7; | ||
103 | color: white; | ||
104 | text-decoration: none; | ||
105 | } | ||
106 | |||
107 | #content h2 a:hover { | ||
108 | text-decoration: underline; | ||
109 | } | ||
110 | |||
111 | #content h3 { | ||
112 | font-style: italic; | ||
113 | padding-top: 15px; | ||
114 | padding-bottom: 4px; | ||
115 | margin-right: 15px; | ||
116 | margin-left: 15px; | ||
117 | margin-bottom: 5px; | ||
118 | border-bottom: solid 1px #bcd; | ||
119 | } | ||
120 | |||
121 | #content h4 { | ||
122 | margin-right: 15px; | ||
123 | margin-left: 15px; | ||
124 | border-bottom: solid 1px #bcd; | ||
125 | } | ||
126 | |||
127 | #content pre { | ||
128 | margin: 15px; | ||
129 | } | ||
130 | |||
131 | pre { | ||
132 | background-color: rgb(50, 55, 68); | ||
133 | color: white; | ||
134 | border-radius: 3px; | ||
135 | /* border: 1px solid #C0C0C0; /* silver */ | ||
136 | padding: 15px; | ||
137 | overflow: auto; | ||
138 | font-family: "Andale Mono", monospace; | ||
139 | } | ||
140 | |||
141 | #content ul pre.example { | ||
142 | margin-left: 0px; | ||
143 | } | ||
144 | |||
145 | table.index { | ||
146 | /* border: 1px #00007f; */ | ||
147 | } | ||
148 | table.index td { text-align: left; vertical-align: top; } | ||
149 | |||
150 | #navigation ul | ||
151 | { | ||
152 | font-size:1em; | ||
153 | list-style-type: none; | ||
154 | margin: 1px 1px 10px 1px; | ||
155 | padding-left: 20px; | ||
156 | } | ||
157 | |||
158 | #navigation li { | ||
159 | text-indent: -1em; | ||
160 | display: block; | ||
161 | margin: 3px 0px 0px 22px; | ||
162 | } | ||
163 | |||
164 | #navigation li li a { | ||
165 | margin: 0px 3px 0px -1em; | ||
166 | } | ||
167 | |||
168 | #content { | ||
169 | margin-left: 14em; | ||
170 | } | ||
171 | |||
172 | #content p { | ||
173 | padding-left: 15px; | ||
174 | padding-right: 15px; | ||
175 | } | ||
176 | |||
177 | #content table { | ||
178 | padding-left: 15px; | ||
179 | padding-right: 15px; | ||
180 | background-color: white; | ||
181 | } | ||
182 | |||
183 | #content p, #content table, #content ol, #content ul, #content dl { | ||
184 | max-width: 900px; | ||
185 | } | ||
186 | |||
187 | #about { | ||
188 | padding: 15px; | ||
189 | padding-left: 16em; | ||
190 | background-color: white; | ||
191 | border-top: 1px solid #d3dbec; | ||
192 | border-bottom: 1px solid #d3dbec; | ||
193 | } | ||
194 | |||
195 | table.module_list, table.function_list { | ||
196 | border-width: 1px; | ||
197 | border-style: solid; | ||
198 | border-color: #cccccc; | ||
199 | border-collapse: collapse; | ||
200 | margin: 15px; | ||
201 | } | ||
202 | table.module_list td, table.function_list td { | ||
203 | border-width: 1px; | ||
204 | padding-left: 10px; | ||
205 | padding-right: 10px; | ||
206 | padding-top: 5px; | ||
207 | padding-bottom: 5px; | ||
208 | border: solid 1px rgb(193, 204, 228); | ||
209 | } | ||
210 | table.module_list td.name, table.function_list td.name { | ||
211 | background-color: white; min-width: 200px; border-right-width: 0px; | ||
212 | } | ||
213 | table.module_list td.summary, table.function_list td.summary { | ||
214 | background-color: white; width: 100%; border-left-width: 0px; | ||
215 | } | ||
216 | |||
217 | dl.function { | ||
218 | margin-right: 15px; | ||
219 | margin-left: 15px; | ||
220 | border-bottom: solid 1px rgb(193, 204, 228); | ||
221 | border-left: solid 1px rgb(193, 204, 228); | ||
222 | border-right: solid 1px rgb(193, 204, 228); | ||
223 | background-color: white; | ||
224 | } | ||
225 | |||
226 | dl.function dt { | ||
227 | color: rgb(99, 123, 188); | ||
228 | font-family: monospace; | ||
229 | border-top: solid 1px rgb(193, 204, 228); | ||
230 | padding: 15px; | ||
231 | } | ||
232 | |||
233 | dl.function dd { | ||
234 | margin-left: 15px; | ||
235 | margin-right: 15px; | ||
236 | margin-top: 5px; | ||
237 | margin-bottom: 15px; | ||
238 | } | ||
239 | |||
240 | #content dl.function dd h3 { | ||
241 | margin-top: 0px; | ||
242 | margin-left: 0px; | ||
243 | padding-left: 0px; | ||
244 | font-size: 16px; | ||
245 | color: rgb(128, 128, 128); | ||
246 | border-bottom: solid 1px #def; | ||
247 | } | ||
248 | |||
249 | #content dl.function dd ul, #content dl.function dd ol { | ||
250 | padding: 0px; | ||
251 | padding-left: 15px; | ||
252 | list-style-type: none; | ||
253 | } | ||
254 | |||
255 | ul.nowrap { | ||
256 | overflow:auto; | ||
257 | white-space:nowrap; | ||
258 | } | ||
259 | |||
260 | .section-description { | ||
261 | padding-left: 15px; | ||
262 | padding-right: 15px; | ||
263 | } | ||
264 | |||
265 | /* stop sublists from having initial vertical space */ | ||
266 | ul ul { margin-top: 0px; } | ||
267 | ol ul { margin-top: 0px; } | ||
268 | ol ol { margin-top: 0px; } | ||
269 | ul ol { margin-top: 0px; } | ||
270 | |||
271 | /* make the target distinct; helps when we're navigating to a function */ | ||
272 | a:target + * { | ||
273 | background-color: #FF9; | ||
274 | } | ||
275 | |||
276 | |||
277 | /* styles for prettification of source */ | ||
278 | pre .comment { color: #bbccaa; } | ||
279 | pre .constant { color: #a8660d; } | ||
280 | pre .escape { color: #844631; } | ||
281 | pre .keyword { color: #ffc090; font-weight: bold; } | ||
282 | pre .library { color: #0e7c6b; } | ||
283 | pre .marker { color: #512b1e; background: #fedc56; font-weight: bold; } | ||
284 | pre .string { color: #8080ff; } | ||
285 | pre .number { color: #f8660d; } | ||
286 | pre .operator { color: #2239a8; font-weight: bold; } | ||
287 | pre .preprocessor, pre .prepro { color: #a33243; } | ||
288 | pre .global { color: #c040c0; } | ||
289 | pre .user-keyword { color: #800080; } | ||
290 | pre .prompt { color: #558817; } | ||
291 | pre .url { color: #272fc2; text-decoration: underline; } | ||
diff --git a/docs/topics/01-introduction.md.html b/docs/topics/01-introduction.md.html new file mode 100644 index 0000000..2901cc9 --- /dev/null +++ b/docs/topics/01-introduction.md.html | |||
@@ -0,0 +1,70 @@ | |||
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
3 | <html> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
5 | <head> | ||
6 | <title>Lua-System docs</title> | ||
7 | <link rel="stylesheet" href="../ldoc.css" type="text/css" /> | ||
8 | </head> | ||
9 | <body> | ||
10 | |||
11 | <div id="container"> | ||
12 | |||
13 | <div id="product"> | ||
14 | <div id="product_logo"></div> | ||
15 | <div id="product_name"><big><b></b></big></div> | ||
16 | <div id="product_description"></div> | ||
17 | </div> <!-- id="product" --> | ||
18 | |||
19 | |||
20 | <div id="main"> | ||
21 | |||
22 | |||
23 | <!-- Menu --> | ||
24 | |||
25 | <div id="navigation"> | ||
26 | <br/> | ||
27 | <h1>Lua-System</h1> | ||
28 | |||
29 | |||
30 | |||
31 | |||
32 | <h2>Topics</h2> | ||
33 | <ul class=""> | ||
34 | <li><strong>1. Introduction</strong></li> | ||
35 | <li><a href="../topics/CHANGELOG.md.html">CHANGELOG</a></li> | ||
36 | <li><a href="../topics/LICENSE.md.html">MIT License</a></li> | ||
37 | </ul> | ||
38 | <h2>Modules</h2> | ||
39 | <ul class="nowrap"> | ||
40 | <li><a href="../index.html">system</a></li> | ||
41 | </ul> | ||
42 | |||
43 | </div> | ||
44 | |||
45 | <div id="content"> | ||
46 | |||
47 | |||
48 | <h1>1. Introduction</h1> | ||
49 | |||
50 | <p>luasystem is a platform independent system call library for Lua. | ||
51 | Supports Unix, Windows, MacOS, <code>Lua >= 5.1</code> and <code>luajit >= 2.0.0</code>.</p> | ||
52 | |||
53 | <p>Lua is typically platform independent, but it requires adhering to very old C | ||
54 | standards. This in turn means that many common features (according to todays standards) | ||
55 | are not available. This module attempts to overcome some of those hurdles by providing | ||
56 | functions that cover those common needs.</p> | ||
57 | |||
58 | <p>This is not a kitchen sink library, but a minimalistic one with a focus on platform | ||
59 | independence.</p> | ||
60 | |||
61 | |||
62 | </div> <!-- id="content" --> | ||
63 | </div> <!-- id="main" --> | ||
64 | <div id="about"> | ||
65 | <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> | ||
66 | <i style="float:right;">Last updated 2023-11-15 07:42:18 </i> | ||
67 | </div> <!-- id="about" --> | ||
68 | </div> <!-- id="container" --> | ||
69 | </body> | ||
70 | </html> | ||
diff --git a/docs/topics/CHANGELOG.md.html b/docs/topics/CHANGELOG.md.html new file mode 100644 index 0000000..f909b4b --- /dev/null +++ b/docs/topics/CHANGELOG.md.html | |||
@@ -0,0 +1,121 @@ | |||
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
3 | <html> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
5 | <head> | ||
6 | <title>Lua-System docs</title> | ||
7 | <link rel="stylesheet" href="../ldoc.css" type="text/css" /> | ||
8 | </head> | ||
9 | <body> | ||
10 | |||
11 | <div id="container"> | ||
12 | |||
13 | <div id="product"> | ||
14 | <div id="product_logo"></div> | ||
15 | <div id="product_name"><big><b></b></big></div> | ||
16 | <div id="product_description"></div> | ||
17 | </div> <!-- id="product" --> | ||
18 | |||
19 | |||
20 | <div id="main"> | ||
21 | |||
22 | |||
23 | <!-- Menu --> | ||
24 | |||
25 | <div id="navigation"> | ||
26 | <br/> | ||
27 | <h1>Lua-System</h1> | ||
28 | |||
29 | |||
30 | <h2>Contents</h2> | ||
31 | <ul> | ||
32 | <li><a href="#Versioning">Versioning </a></li> | ||
33 | <li><a href="#Version_history">Version history </a></li> | ||
34 | </ul> | ||
35 | |||
36 | |||
37 | <h2>Topics</h2> | ||
38 | <ul class=""> | ||
39 | <li><a href="../topics/01-introduction.md.html">1. Introduction</a></li> | ||
40 | <li><strong>CHANGELOG</strong></li> | ||
41 | <li><a href="../topics/LICENSE.md.html">MIT License</a></li> | ||
42 | </ul> | ||
43 | <h2>Modules</h2> | ||
44 | <ul class="nowrap"> | ||
45 | <li><a href="../index.html">system</a></li> | ||
46 | </ul> | ||
47 | |||
48 | </div> | ||
49 | |||
50 | <div id="content"> | ||
51 | |||
52 | |||
53 | <h1>CHANGELOG</h1> | ||
54 | |||
55 | <p><a name="Versioning"></a></p> | ||
56 | <h2>Versioning</h2> | ||
57 | |||
58 | <p>This library is versioned based on Semantic Versioning (<a href="https://semver.org/">SemVer</a>).</p> | ||
59 | |||
60 | <h4>Version scoping</h4> | ||
61 | |||
62 | <p>The scope of what is covered by the version number excludes:</p> | ||
63 | |||
64 | <ul> | ||
65 | <li>error messages; the text of the messages can change, unless specifically documented.</li> | ||
66 | </ul> | ||
67 | |||
68 | <h4>Releasing new versions</h4> | ||
69 | |||
70 | <ul> | ||
71 | <li>create a release branch</li> | ||
72 | <li>update the changelog below</li> | ||
73 | <li>update version and copyright-years in <code>./LICENSE.md</code> and <code>./src/time.c</code> (in module constants)</li> | ||
74 | <li>create a new rockspec and update the version inside the new rockspec:<br/> | ||
75 | <code>cp luasystem-scm-0.rockspec ./rockspecs/luasystem-X.Y.Z-1.rockspec</code></li> | ||
76 | <li>clean and render the docs: run <code>ldoc .</code></li> | ||
77 | <li>commit the changes as <code>Release vX.Y.Z</code></li> | ||
78 | <li>push the commit, and create a release PR</li> | ||
79 | <li>after merging tag the release commit with <code>vX.Y.Z</code></li> | ||
80 | <li>upload to LuaRocks:<br/> | ||
81 | <code>luarocks upload ./rockspecs/luasystem-X.Y.Z-1.rockspec --api-key=ABCDEFGH</code></li> | ||
82 | <li>test the newly created rock:<br/> | ||
83 | <code>luarocks install luasystem</code></li> | ||
84 | </ul> | ||
85 | |||
86 | <p><a name="Version_history"></a></p> | ||
87 | <h2>Version history</h2> | ||
88 | |||
89 | <h3>Version X.Y.Z, unreleased</h3> | ||
90 | |||
91 | <ul> | ||
92 | <li>Feat: on Windows <a href="../index.html#sleep">sleep</a> now has a precision parameter</li> | ||
93 | <li>Feat: <a href="../index.html#setenv">setenv</a> added to set environment variables.</li> | ||
94 | <li>Feat: <a href="../index.html#getenvs">getenvs</a> added to list environment variables.</li> | ||
95 | <li>Feat: <a href="../index.html#getenv">getenv</a> added to get environment variable previously set (Windows).</li> | ||
96 | <li>Feat: <a href="../index.html#random">random</a> added to return high-quality random bytes</li> | ||
97 | <li>Feat: <a href="../index.html#isatty">isatty</a> added to check if a file-handle is a tty</li> | ||
98 | </ul> | ||
99 | |||
100 | <h3>Version 0.2.1, released 02-Oct-2016</h3> | ||
101 | |||
102 | <h3>Version 0.2.0, released 08-May-2016</h3> | ||
103 | |||
104 | <h3>Version 0.1.1, released 10-Apr-2016</h3> | ||
105 | |||
106 | <h3>Version 0.1.0, released 11-Feb-2016</h3> | ||
107 | |||
108 | <ul> | ||
109 | <li>initial release</li> | ||
110 | </ul> | ||
111 | |||
112 | |||
113 | </div> <!-- id="content" --> | ||
114 | </div> <!-- id="main" --> | ||
115 | <div id="about"> | ||
116 | <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> | ||
117 | <i style="float:right;">Last updated 2023-11-15 07:42:18 </i> | ||
118 | </div> <!-- id="about" --> | ||
119 | </div> <!-- id="container" --> | ||
120 | </body> | ||
121 | </html> | ||
diff --git a/docs/topics/LICENSE.md.html b/docs/topics/LICENSE.md.html new file mode 100644 index 0000000..67614d2 --- /dev/null +++ b/docs/topics/LICENSE.md.html | |||
@@ -0,0 +1,79 @@ | |||
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
3 | <html> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
5 | <head> | ||
6 | <title>Lua-System docs</title> | ||
7 | <link rel="stylesheet" href="../ldoc.css" type="text/css" /> | ||
8 | </head> | ||
9 | <body> | ||
10 | |||
11 | <div id="container"> | ||
12 | |||
13 | <div id="product"> | ||
14 | <div id="product_logo"></div> | ||
15 | <div id="product_name"><big><b></b></big></div> | ||
16 | <div id="product_description"></div> | ||
17 | </div> <!-- id="product" --> | ||
18 | |||
19 | |||
20 | <div id="main"> | ||
21 | |||
22 | |||
23 | <!-- Menu --> | ||
24 | |||
25 | <div id="navigation"> | ||
26 | <br/> | ||
27 | <h1>Lua-System</h1> | ||
28 | |||
29 | |||
30 | |||
31 | |||
32 | <h2>Topics</h2> | ||
33 | <ul class=""> | ||
34 | <li><a href="../topics/01-introduction.md.html">1. Introduction</a></li> | ||
35 | <li><a href="../topics/CHANGELOG.md.html">CHANGELOG</a></li> | ||
36 | <li><strong>MIT License</strong></li> | ||
37 | </ul> | ||
38 | <h2>Modules</h2> | ||
39 | <ul class="nowrap"> | ||
40 | <li><a href="../index.html">system</a></li> | ||
41 | </ul> | ||
42 | |||
43 | </div> | ||
44 | |||
45 | <div id="content"> | ||
46 | |||
47 | |||
48 | <h1>MIT License</h1> | ||
49 | |||
50 | <h3>Copyright (c) 2016-2023 Oscar Lim</h3> | ||
51 | |||
52 | <p>Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
53 | this software and associated documentation files (the "Software"), to deal in | ||
54 | the Software without restriction, including without limitation the rights to | ||
55 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
56 | of the Software, and to permit persons to whom the Software is furnished to do | ||
57 | so, subject to the following conditions:</p> | ||
58 | |||
59 | <p>The above copyright notice and this permission notice shall be included in all | ||
60 | copies or substantial portions of the Software.</p> | ||
61 | |||
62 | <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
63 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
64 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
65 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
66 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
67 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
68 | SOFTWARE.</p> | ||
69 | |||
70 | |||
71 | </div> <!-- id="content" --> | ||
72 | </div> <!-- id="main" --> | ||
73 | <div id="about"> | ||
74 | <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> | ||
75 | <i style="float:right;">Last updated 2023-11-15 07:42:18 </i> | ||
76 | </div> <!-- id="about" --> | ||
77 | </div> <!-- id="container" --> | ||
78 | </body> | ||
79 | </html> | ||
diff --git a/luasystem-scm-0.rockspec b/luasystem-scm-0.rockspec index 74e301d..86209a6 100644 --- a/luasystem-scm-0.rockspec +++ b/luasystem-scm-0.rockspec | |||
@@ -11,7 +11,7 @@ version = package_version.."-"..rockspec_revision | |||
11 | source = { | 11 | source = { |
12 | url = "git+https://github.com/"..github_account_name.."/"..github_repo_name..".git", | 12 | url = "git+https://github.com/"..github_account_name.."/"..github_repo_name..".git", |
13 | branch = (package_version == "scm") and "master" or nil, | 13 | branch = (package_version == "scm") and "master" or nil, |
14 | tag = (package_version ~= "scm") and package_version or nil, | 14 | tag = (package_version ~= "scm") and "v"..package_version or nil, |
15 | } | 15 | } |
16 | 16 | ||
17 | description = { | 17 | description = { |
@@ -39,13 +39,20 @@ local function make_platform(plat) | |||
39 | linux = { "rt" }, | 39 | linux = { "rt" }, |
40 | unix = { }, | 40 | unix = { }, |
41 | macosx = { }, | 41 | macosx = { }, |
42 | win32 = { }, | 42 | win32 = { "advapi32", "winmm" }, |
43 | mingw32 = { }, | 43 | mingw32 = { }, |
44 | } | 44 | } |
45 | return { | 45 | return { |
46 | modules = { | 46 | modules = { |
47 | ['system.core'] = { | 47 | ['system.core'] = { |
48 | sources = { 'src/core.c', 'src/compat.c', 'src/time.c', }, | 48 | sources = { |
49 | 'src/core.c', | ||
50 | 'src/compat.c', | ||
51 | 'src/time.c', | ||
52 | 'src/environment.c', | ||
53 | 'src/random.c', | ||
54 | 'src/term.c', | ||
55 | }, | ||
49 | defines = defines[plat], | 56 | defines = defines[plat], |
50 | libraries = libraries[plat], | 57 | libraries = libraries[plat], |
51 | }, | 58 | }, |
diff --git a/rockspecs/luasystem-0.2.1-1.rockspec b/rockspecs/luasystem-0.2.1-1.rockspec index 7d8b9b0..e14118d 100644 --- a/rockspecs/luasystem-0.2.1-1.rockspec +++ b/rockspecs/luasystem-0.2.1-1.rockspec | |||
@@ -11,7 +11,7 @@ version = package_version.."-"..rockspec_revision | |||
11 | source = { | 11 | source = { |
12 | url = "git+https://github.com/"..github_account_name.."/"..github_repo_name..".git", | 12 | url = "git+https://github.com/"..github_account_name.."/"..github_repo_name..".git", |
13 | branch = (package_version == "scm") and "master" or nil, | 13 | branch = (package_version == "scm") and "master" or nil, |
14 | tag = (package_version ~= "scm") and package_version or nil, | 14 | tag = (package_version ~= "scm") and "v"..package_version or nil, |
15 | } | 15 | } |
16 | 16 | ||
17 | description = { | 17 | description = { |
diff --git a/spec/01-time_spec.lua b/spec/01-time_spec.lua new file mode 100644 index 0000000..1607cca --- /dev/null +++ b/spec/01-time_spec.lua | |||
@@ -0,0 +1,76 @@ | |||
1 | local system = require 'system.core' | ||
2 | |||
3 | describe('Test time functions', function() | ||
4 | |||
5 | -- returns the new second, on the new second | ||
6 | local function wait_for_second_rollover() | ||
7 | local start_time = math.floor(os.time()) | ||
8 | local end_time = math.floor(os.time()) | ||
9 | while end_time == start_time do | ||
10 | end_time = math.floor(os.time()) | ||
11 | end | ||
12 | return end_time | ||
13 | end | ||
14 | |||
15 | |||
16 | describe("time()", function() | ||
17 | |||
18 | it('returns current time', function() | ||
19 | local expected_time = wait_for_second_rollover() | ||
20 | local received_time = system.gettime() | ||
21 | assert.is.near(expected_time, received_time, 0.02) | ||
22 | |||
23 | wait_for_second_rollover() | ||
24 | assert.is.near(1, system.gettime() - received_time, 0.02) | ||
25 | end) | ||
26 | |||
27 | end) | ||
28 | |||
29 | |||
30 | |||
31 | describe("monotime()", function() | ||
32 | |||
33 | it('returns monotonically increasing time', function() | ||
34 | local starttime = system.monotime() | ||
35 | local endtime = system.monotime() | ||
36 | local delta = endtime - starttime | ||
37 | assert.is_true(starttime > 0) | ||
38 | assert.is_true(delta >= 0) | ||
39 | assert.is_true(system.monotime() - endtime >= 0) | ||
40 | end) | ||
41 | |||
42 | end) | ||
43 | |||
44 | |||
45 | |||
46 | describe("sleep()", function() | ||
47 | |||
48 | it("should sleep for the specified time", function() | ||
49 | local start_time = system.gettime() | ||
50 | system.sleep(1, 1) | ||
51 | local end_time = system.gettime() | ||
52 | local elapsed_time = end_time - start_time | ||
53 | assert.is.near(elapsed_time, 1, 0.2) -- large marging of error due to CI priorities | ||
54 | end) | ||
55 | |||
56 | |||
57 | it("should sleep for the specified time; fractional", function() | ||
58 | local start_time = system.gettime() | ||
59 | system.sleep(0.5, 1) | ||
60 | local end_time = system.gettime() | ||
61 | local elapsed_time = end_time - start_time | ||
62 | assert.is.near(0.5, elapsed_time, 0.2) -- large marging of error due to CI priorities | ||
63 | end) | ||
64 | |||
65 | |||
66 | it("should return immediately for a non-positive sleep time", function() | ||
67 | local start_time = system.gettime() | ||
68 | system.sleep(-1) | ||
69 | local end_time = system.gettime() | ||
70 | local elapsed_time = end_time - start_time | ||
71 | assert.is.near(elapsed_time, 0, 0.01) | ||
72 | end) | ||
73 | |||
74 | end) | ||
75 | |||
76 | end) | ||
diff --git a/spec/02-random_spec.lua b/spec/02-random_spec.lua new file mode 100644 index 0000000..23b6d95 --- /dev/null +++ b/spec/02-random_spec.lua | |||
@@ -0,0 +1,47 @@ | |||
1 | local system = require("system") | ||
2 | |||
3 | describe("Random:", function() | ||
4 | |||
5 | describe("random()", function() | ||
6 | |||
7 | it("should return random bytes for a valid number of bytes", function() | ||
8 | local num_bytes = 1 | ||
9 | local result, err_msg = system.random(num_bytes) | ||
10 | assert.is_nil(err_msg) | ||
11 | assert.is.string(result) | ||
12 | assert.is_equal(num_bytes, #result) | ||
13 | end) | ||
14 | |||
15 | |||
16 | it("should return an empty string for 0 bytes", function() | ||
17 | local num_bytes = 0 | ||
18 | local result, err_msg = system.random(num_bytes) | ||
19 | assert.is_nil(err_msg) | ||
20 | assert.are.equal("", result) | ||
21 | end) | ||
22 | |||
23 | |||
24 | it("should return an error message for an invalid number of bytes", function() | ||
25 | local num_bytes = -1 | ||
26 | local result, err_msg = system.random(num_bytes) | ||
27 | assert.is.falsy(result) | ||
28 | assert.are.equal("invalid number of bytes, must not be less than 0", err_msg) | ||
29 | end) | ||
30 | |||
31 | |||
32 | it("should not return duplicate results", function() | ||
33 | local num_bytes = 1025 | ||
34 | local result1, err_msg = system.random(num_bytes) | ||
35 | assert.is_nil(err_msg) | ||
36 | assert.is.string(result1) | ||
37 | |||
38 | local result2, err_msg = system.random(num_bytes) | ||
39 | assert.is_nil(err_msg) | ||
40 | assert.is.string(result2) | ||
41 | |||
42 | assert.is_not.equal(result1, result2) | ||
43 | end) | ||
44 | |||
45 | end) | ||
46 | |||
47 | end) | ||
diff --git a/spec/03-environment_spec.lua b/spec/03-environment_spec.lua new file mode 100644 index 0000000..842ed6f --- /dev/null +++ b/spec/03-environment_spec.lua | |||
@@ -0,0 +1,81 @@ | |||
1 | -- Import the library that contains the environment-related functions | ||
2 | local system = require("system") | ||
3 | |||
4 | describe("Environment Variables:", function() | ||
5 | |||
6 | describe("setenv()", function() | ||
7 | |||
8 | it("should set an environment variable", function() | ||
9 | assert.is_true(system.setenv("TEST_VAR", "test_value")) | ||
10 | assert.is_equal("test_value", system.getenv("TEST_VAR")) | ||
11 | end) | ||
12 | |||
13 | |||
14 | local func = system.windows and pending or it --pending on Windows | ||
15 | -- Windows will unset a variable if set as an empty string | ||
16 | func("should set an empty environment variable value", function() | ||
17 | assert.is_true(system.setenv("TEST_VAR", "")) | ||
18 | assert.is_equal("", system.getenv("TEST_VAR")) | ||
19 | end) | ||
20 | |||
21 | |||
22 | it("should unset an environment variable on nil", function() | ||
23 | assert.is_true(system.setenv("TEST_VAR", "test_value")) | ||
24 | assert.is_equal("test_value", system.getenv("TEST_VAR")) | ||
25 | |||
26 | assert.is_true(system.setenv("TEST_VAR", nil)) | ||
27 | assert.is_nil(system.getenv("TEST_VAR")) | ||
28 | end) | ||
29 | |||
30 | |||
31 | it("should error on input bad type", function() | ||
32 | assert.has_error(function() | ||
33 | system.setenv("TEST_VAR", {}) | ||
34 | end) | ||
35 | assert.has_error(function() | ||
36 | system.setenv({}, "test_value") | ||
37 | end) | ||
38 | end) | ||
39 | |||
40 | |||
41 | it("should return success on deleting a variable that doesn't exist", function() | ||
42 | if system.getenv("TEST_VAR") ~= nil then | ||
43 | -- clear if it was already set | ||
44 | assert.is_true(system.setenv("TEST_VAR", nil)) | ||
45 | end | ||
46 | |||
47 | assert.is_true(system.setenv("TEST_VAR", nil)) -- clear again shouldn't fail | ||
48 | end) | ||
49 | |||
50 | end) | ||
51 | |||
52 | |||
53 | |||
54 | describe("getenvs()", function() | ||
55 | |||
56 | it("should list environment variables", function() | ||
57 | assert.is_true(system.setenv("TEST_VAR1", nil)) | ||
58 | assert.is_true(system.setenv("TEST_VAR2", nil)) | ||
59 | assert.is_true(system.setenv("TEST_VAR3", nil)) | ||
60 | local envVars1 = system.getenvs() | ||
61 | assert.is_true(system.setenv("TEST_VAR1", "test_value1")) | ||
62 | assert.is_true(system.setenv("TEST_VAR2", "test_value2")) | ||
63 | assert.is_true(system.setenv("TEST_VAR3", "test_value3")) | ||
64 | local envVars2 = system.getenvs() | ||
65 | assert.is_true(system.setenv("TEST_VAR1", nil)) | ||
66 | assert.is_true(system.setenv("TEST_VAR2", nil)) | ||
67 | assert.is_true(system.setenv("TEST_VAR3", nil)) | ||
68 | |||
69 | for k,v in pairs(envVars1) do | ||
70 | envVars2[k] = nil | ||
71 | end | ||
72 | assert.are.same({ | ||
73 | TEST_VAR1 = "test_value1", | ||
74 | TEST_VAR2 = "test_value2", | ||
75 | TEST_VAR3 = "test_value3", | ||
76 | }, envVars2) | ||
77 | end) | ||
78 | |||
79 | end) | ||
80 | |||
81 | end) | ||
diff --git a/spec/time_spec.lua b/spec/time_spec.lua deleted file mode 100644 index a017cfe..0000000 --- a/spec/time_spec.lua +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | local system = require 'system.core' | ||
2 | |||
3 | describe('Test time functions', function() | ||
4 | it('gettime returns current time', function() | ||
5 | local starttime = system.gettime() | ||
6 | local expected = os.time() | ||
7 | local endtime = system.gettime() | ||
8 | local delta = endtime - starttime | ||
9 | local avg = starttime + delta/2 | ||
10 | assert.is_true(expected >= math.floor(starttime)) | ||
11 | assert.is_true(expected <= math.ceil(endtime)) | ||
12 | assert.is_near(expected, avg, 1 + delta) | ||
13 | end) | ||
14 | |||
15 | it('monottime returns monotonically increasing time', function() | ||
16 | local starttime = system.monotime() | ||
17 | local endtime = system.monotime() | ||
18 | local delta = endtime - starttime | ||
19 | assert.is_true(starttime > 0) | ||
20 | assert.is_true(delta >= 0) | ||
21 | assert.is_true(system.monotime() - endtime >= 0) | ||
22 | end) | ||
23 | |||
24 | it('sleep will wait for specified amount of time', function() | ||
25 | local starttime = system.gettime() | ||
26 | local starttick = system.monotime() | ||
27 | system.sleep(0.5) | ||
28 | assert.is_near(0.5, system.gettime() - starttime, 0.15) | ||
29 | assert.is_near(0.5, system.monotime() - starttick, 0.15) | ||
30 | end) | ||
31 | end) | ||
diff --git a/src/Makefile b/src/Makefile index 10fc31a..b4ed16f 100644 --- a/src/Makefile +++ b/src/Makefile | |||
@@ -85,7 +85,7 @@ PLATFORM_win32?=Release | |||
85 | CDIR_win32?=bin/lua/$(LUA_VERSION)/$(PLATFORM_win32) | 85 | CDIR_win32?=bin/lua/$(LUA_VERSION)/$(PLATFORM_win32) |
86 | LDIR_win32?=bin/lua/$(LUA_VERSION)/$(PLATFORM_win32)/lua | 86 | LDIR_win32?=bin/lua/$(LUA_VERSION)/$(PLATFORM_win32)/lua |
87 | LUALIB_win32?=$(LUAPREFIX_win32)/lib/lua/$(LUA_VERSION)/$(PLATFORM_win32) | 87 | LUALIB_win32?=$(LUAPREFIX_win32)/lib/lua/$(LUA_VERSION)/$(PLATFORM_win32) |
88 | LUALIBNAME_win32?=lua$(subst .,,$(LUA_VERSION)).lib | 88 | LUALIBNAME_win32?=lua$(subst .,,$(LUA_VERSION)).lib |
89 | 89 | ||
90 | 90 | ||
91 | # prefix: /usr/local /usr /opt/local /sw | 91 | # prefix: /usr/local /usr /opt/local /sw |
@@ -217,7 +217,7 @@ LUALIB= $(LUALIB_$(PLAT)) | |||
217 | #------ | 217 | #------ |
218 | # Objects | 218 | # Objects |
219 | # | 219 | # |
220 | OBJS=core.$(O) compat.$(O) time.$(O) | 220 | OBJS=core.$(O) compat.$(O) time.$(O) environment.$(O) random.$(O) term.$(O) |
221 | 221 | ||
222 | #------ | 222 | #------ |
223 | # Targets | 223 | # Targets |
diff --git a/src/compat.h b/src/compat.h index f523fd9..5aca6df 100644 --- a/src/compat.h +++ b/src/compat.h | |||
@@ -8,4 +8,31 @@ | |||
8 | void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); | 8 | void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); |
9 | #endif | 9 | #endif |
10 | 10 | ||
11 | // Windows doesn't have ssize_t, so we define it here | ||
12 | #ifdef _WIN32 | ||
13 | #if SIZE_MAX == UINT_MAX | ||
14 | typedef int ssize_t; /* common 32 bit case */ | ||
15 | #define SSIZE_MIN INT_MIN | ||
16 | #define SSIZE_MAX INT_MAX | ||
17 | #elif SIZE_MAX == ULONG_MAX | ||
18 | typedef long ssize_t; /* linux 64 bits */ | ||
19 | #define SSIZE_MIN LONG_MIN | ||
20 | #define SSIZE_MAX LONG_MAX | ||
21 | #elif SIZE_MAX == ULLONG_MAX | ||
22 | typedef long long ssize_t; /* windows 64 bits */ | ||
23 | #define SSIZE_MIN LLONG_MIN | ||
24 | #define SSIZE_MAX LLONG_MAX | ||
25 | #elif SIZE_MAX == USHRT_MAX | ||
26 | typedef short ssize_t; /* is this even possible? */ | ||
27 | #define SSIZE_MIN SHRT_MIN | ||
28 | #define SSIZE_MAX SHRT_MAX | ||
29 | #elif SIZE_MAX == UINTMAX_MAX | ||
30 | typedef intmax_t ssize_t; /* last resort, chux suggestion */ | ||
31 | #define SSIZE_MIN INTMAX_MIN | ||
32 | #define SSIZE_MAX INTMAX_MAX | ||
33 | #else | ||
34 | #error platform has exotic SIZE_MAX | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
11 | #endif | 38 | #endif |
@@ -1,3 +1,6 @@ | |||
1 | /// Platform independent system calls for Lua. | ||
2 | // @module system | ||
3 | |||
1 | #include <lua.h> | 4 | #include <lua.h> |
2 | #include <lauxlib.h> | 5 | #include <lauxlib.h> |
3 | 6 | ||
@@ -10,6 +13,9 @@ | |||
10 | #endif | 13 | #endif |
11 | 14 | ||
12 | void time_open(lua_State *L); | 15 | void time_open(lua_State *L); |
16 | void environment_open(lua_State *L); | ||
17 | void random_open(lua_State *L); | ||
18 | void term_open(lua_State *L); | ||
13 | 19 | ||
14 | /*------------------------------------------------------------------------- | 20 | /*------------------------------------------------------------------------- |
15 | * Initializes all library modules. | 21 | * Initializes all library modules. |
@@ -19,6 +25,16 @@ LUAEXPORT int luaopen_system_core(lua_State *L) { | |||
19 | lua_pushstring(L, "_VERSION"); | 25 | lua_pushstring(L, "_VERSION"); |
20 | lua_pushstring(L, LUASYSTEM_VERSION); | 26 | lua_pushstring(L, LUASYSTEM_VERSION); |
21 | lua_rawset(L, -3); | 27 | lua_rawset(L, -3); |
28 | lua_pushstring(L, "windows"); | ||
29 | #ifdef _WIN32 | ||
30 | lua_pushboolean(L, 1); | ||
31 | #else | ||
32 | lua_pushboolean(L, 0); | ||
33 | #endif | ||
34 | lua_rawset(L, -3); | ||
22 | time_open(L); | 35 | time_open(L); |
36 | random_open(L); | ||
37 | term_open(L); | ||
38 | environment_open(L); | ||
23 | return 1; | 39 | return 1; |
24 | } | 40 | } |
diff --git a/src/environment.c b/src/environment.c new file mode 100644 index 0000000..5f1c3da --- /dev/null +++ b/src/environment.c | |||
@@ -0,0 +1,173 @@ | |||
1 | /// @submodule system | ||
2 | #include <lua.h> | ||
3 | #include <lauxlib.h> | ||
4 | #include "compat.h" | ||
5 | #include <stdlib.h> | ||
6 | #include <string.h> | ||
7 | |||
8 | #ifdef _WIN32 | ||
9 | #include "windows.h" | ||
10 | #endif | ||
11 | |||
12 | /*** | ||
13 | Gets the value of an environment variable. | ||
14 | |||
15 | __NOTE__: Windows has multiple copies of environment variables. For this reason, | ||
16 | the `setenv` function will not work with Lua's `os.getenv` on Windows. If you want | ||
17 | to use `setenv` then consider patching `os.getenv` with this implementation of `getenv`. | ||
18 | @function getenv | ||
19 | @tparam string name name of the environment variable | ||
20 | @treturn string|nil value of the environment variable, or nil if the variable is not set | ||
21 | */ | ||
22 | static int lua_get_environment_variable(lua_State* L) { | ||
23 | const char* variableName = luaL_checkstring(L, 1); | ||
24 | |||
25 | #ifdef _WIN32 | ||
26 | // On Windows, use GetEnvironmentVariable to retrieve the value | ||
27 | DWORD bufferSize = GetEnvironmentVariable(variableName, NULL, 0); | ||
28 | if (bufferSize > 0) { | ||
29 | char* buffer = (char*)malloc(bufferSize); | ||
30 | if (GetEnvironmentVariable(variableName, buffer, bufferSize) > 0) { | ||
31 | lua_pushstring(L, buffer); | ||
32 | free(buffer); | ||
33 | return 1; | ||
34 | } | ||
35 | free(buffer); | ||
36 | } | ||
37 | #else | ||
38 | // On non-Windows platforms, use getenv to retrieve the value | ||
39 | const char* variableValue = getenv(variableName); | ||
40 | if (variableValue != NULL) { | ||
41 | lua_pushstring(L, variableValue); | ||
42 | return 1; | ||
43 | } | ||
44 | #endif | ||
45 | |||
46 | // If the variable is not set or an error occurs, push nil | ||
47 | lua_pushnil(L); | ||
48 | return 1; | ||
49 | } | ||
50 | |||
51 | |||
52 | /*** | ||
53 | Returns a table with all environment variables. | ||
54 | @function getenvs | ||
55 | @treturn table table with all environment variables and their values | ||
56 | */ | ||
57 | static int lua_list_environment_variables(lua_State* L) { | ||
58 | lua_newtable(L); | ||
59 | |||
60 | #ifdef _WIN32 | ||
61 | char* envStrings = GetEnvironmentStrings(); | ||
62 | char* envString = envStrings; | ||
63 | |||
64 | if (envStrings == NULL) { | ||
65 | lua_pushnil(L); | ||
66 | return 1; | ||
67 | } | ||
68 | |||
69 | while (*envString != '\0') { | ||
70 | const char* envVar = envString; | ||
71 | |||
72 | // Split the environment variable into key and value | ||
73 | char* equals = strchr(envVar, '='); | ||
74 | if (equals != NULL) { | ||
75 | lua_pushlstring(L, envVar, equals - envVar); // Push the key | ||
76 | lua_pushstring(L, equals + 1); // Push the value | ||
77 | lua_settable(L, -3); // Set the key-value pair in the table | ||
78 | } | ||
79 | |||
80 | envString += strlen(envString) + 1; | ||
81 | } | ||
82 | |||
83 | FreeEnvironmentStrings(envStrings); | ||
84 | #else | ||
85 | extern char** environ; | ||
86 | |||
87 | if (environ != NULL) { | ||
88 | for (char** envVar = environ; *envVar != NULL; envVar++) { | ||
89 | const char* envVarStr = *envVar; | ||
90 | |||
91 | // Split the environment variable into key and value | ||
92 | char* equals = strchr(envVarStr, '='); | ||
93 | if (equals != NULL) { | ||
94 | lua_pushlstring(L, envVarStr, equals - envVarStr); // Push the key | ||
95 | lua_pushstring(L, equals + 1); // Push the value | ||
96 | lua_settable(L, -3); // Set the key-value pair in the table | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | #endif | ||
101 | |||
102 | return 1; | ||
103 | } | ||
104 | |||
105 | |||
106 | /*** | ||
107 | Sets an environment variable. | ||
108 | |||
109 | __NOTE__: Windows has multiple copies of environment variables. For this reason, the | ||
110 | `setenv` function will not work with Lua's `os.getenv` on Windows. If you want to use | ||
111 | it then consider patching `os.getenv` with the implementation of `system.getenv`. | ||
112 | @function setenv | ||
113 | @tparam string name name of the environment variable | ||
114 | @tparam[opt] string value value of the environment variable, if `nil` the variable will be deleted (on | ||
115 | Windows, setting an empty string, will also delete the variable) | ||
116 | @treturn boolean success | ||
117 | */ | ||
118 | static int lua_set_environment_variable(lua_State* L) { | ||
119 | const char* variableName = luaL_checkstring(L, 1); | ||
120 | const char* variableValue = luaL_optstring(L, 2, NULL); | ||
121 | |||
122 | #ifdef _WIN32 | ||
123 | // if (variableValue == NULL) { | ||
124 | // // If the value is nil, delete the environment variable | ||
125 | // if (SetEnvironmentVariable(variableName, NULL)) { | ||
126 | // lua_pushboolean(L, 1); | ||
127 | // } else { | ||
128 | // lua_pushboolean(L, 0); | ||
129 | // } | ||
130 | // } else { | ||
131 | // Set the environment variable with the provided value | ||
132 | if (SetEnvironmentVariable(variableName, variableValue)) { | ||
133 | lua_pushboolean(L, 1); | ||
134 | } else { | ||
135 | lua_pushboolean(L, 0); | ||
136 | } | ||
137 | // } | ||
138 | #else | ||
139 | if (variableValue == NULL) { | ||
140 | // If the value is nil, delete the environment variable | ||
141 | if (unsetenv(variableName) == 0) { | ||
142 | lua_pushboolean(L, 1); | ||
143 | } else { | ||
144 | lua_pushboolean(L, 0); | ||
145 | } | ||
146 | } else { | ||
147 | // Set the environment variable with the provided value | ||
148 | if (setenv(variableName, variableValue, 1) == 0) { | ||
149 | lua_pushboolean(L, 1); | ||
150 | } else { | ||
151 | lua_pushboolean(L, 0); | ||
152 | } | ||
153 | } | ||
154 | #endif | ||
155 | |||
156 | return 1; | ||
157 | } | ||
158 | |||
159 | |||
160 | |||
161 | static luaL_Reg func[] = { | ||
162 | { "getenv", lua_get_environment_variable }, | ||
163 | { "setenv", lua_set_environment_variable }, | ||
164 | { "getenvs", lua_list_environment_variables }, | ||
165 | { NULL, NULL } | ||
166 | }; | ||
167 | |||
168 | /*------------------------------------------------------------------------- | ||
169 | * Initializes module | ||
170 | *-------------------------------------------------------------------------*/ | ||
171 | void environment_open(lua_State *L) { | ||
172 | luaL_setfuncs(L, func, 0); | ||
173 | } | ||
diff --git a/src/random.c b/src/random.c new file mode 100644 index 0000000..90fb3f2 --- /dev/null +++ b/src/random.c | |||
@@ -0,0 +1,117 @@ | |||
1 | /// @submodule system | ||
2 | #include <lua.h> | ||
3 | #include <lauxlib.h> | ||
4 | #include "compat.h" | ||
5 | #include <fcntl.h> | ||
6 | |||
7 | #ifdef _WIN32 | ||
8 | #include "windows.h" | ||
9 | #include "wincrypt.h" | ||
10 | #else | ||
11 | #include <errno.h> | ||
12 | #include <unistd.h> | ||
13 | #include <string.h> | ||
14 | #endif | ||
15 | |||
16 | |||
17 | /*** | ||
18 | Generate random bytes. | ||
19 | This uses `CryptGenRandom()` on Windows, and `/dev/urandom` on other platforms. It will return the | ||
20 | requested number of bytes, or an error, never a partial result. | ||
21 | @function random | ||
22 | @tparam[opt=1] int length number of bytes to get | ||
23 | @treturn[1] string string of random bytes | ||
24 | @treturn[2] nil | ||
25 | @treturn[2] string error message | ||
26 | */ | ||
27 | static int lua_get_random_bytes(lua_State* L) { | ||
28 | int num_bytes = luaL_optinteger(L, 1, 1); // Number of bytes, default to 1 if not provided | ||
29 | |||
30 | if (num_bytes <= 0) { | ||
31 | if (num_bytes == 0) { | ||
32 | lua_pushliteral(L, ""); | ||
33 | return 1; | ||
34 | } | ||
35 | lua_pushnil(L); | ||
36 | lua_pushstring(L, "invalid number of bytes, must not be less than 0"); | ||
37 | return 2; | ||
38 | } | ||
39 | |||
40 | unsigned char* buffer = (unsigned char*)lua_newuserdata(L, num_bytes); | ||
41 | if (buffer == NULL) { | ||
42 | lua_pushnil(L); | ||
43 | lua_pushstring(L, "failed to allocate memory for random buffer"); | ||
44 | return 2; | ||
45 | } | ||
46 | |||
47 | ssize_t n; | ||
48 | ssize_t total_read = 0; | ||
49 | |||
50 | #ifdef _WIN32 | ||
51 | HCRYPTPROV hCryptProv; | ||
52 | if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { | ||
53 | DWORD error = GetLastError(); | ||
54 | lua_pushnil(L); | ||
55 | lua_pushfstring(L, "failed to acquire cryptographic context: %lu", error); | ||
56 | return 2; | ||
57 | } | ||
58 | |||
59 | if (!CryptGenRandom(hCryptProv, num_bytes, buffer)) { | ||
60 | DWORD error = GetLastError(); | ||
61 | lua_pushnil(L); | ||
62 | lua_pushfstring(L, "failed to get random data: %lu", error); | ||
63 | CryptReleaseContext(hCryptProv, 0); | ||
64 | return 2; | ||
65 | } | ||
66 | |||
67 | CryptReleaseContext(hCryptProv, 0); | ||
68 | #else | ||
69 | |||
70 | // for macOS/unixes use /dev/urandom for non-blocking | ||
71 | int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); | ||
72 | if (fd < 0) { | ||
73 | lua_pushnil(L); | ||
74 | lua_pushstring(L, "failed opening /dev/urandom"); | ||
75 | return 2; | ||
76 | } | ||
77 | |||
78 | while (total_read < num_bytes) { | ||
79 | n = read(fd, buffer + total_read, num_bytes - total_read); | ||
80 | |||
81 | if (n < 0) { | ||
82 | if (errno == EINTR) { | ||
83 | continue; // Interrupted, retry | ||
84 | |||
85 | } else { | ||
86 | lua_pushnil(L); | ||
87 | lua_pushfstring(L, "failed reading /dev/urandom: %s", strerror(errno)); | ||
88 | close(fd); | ||
89 | return 2; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | total_read += n; | ||
94 | } | ||
95 | |||
96 | close(fd); | ||
97 | #endif | ||
98 | |||
99 | lua_pushlstring(L, (const char*)buffer, num_bytes); | ||
100 | return 1; | ||
101 | } | ||
102 | |||
103 | |||
104 | |||
105 | static luaL_Reg func[] = { | ||
106 | { "random", lua_get_random_bytes }, | ||
107 | { NULL, NULL } | ||
108 | }; | ||
109 | |||
110 | |||
111 | |||
112 | /*------------------------------------------------------------------------- | ||
113 | * Initializes module | ||
114 | *-------------------------------------------------------------------------*/ | ||
115 | void random_open(lua_State *L) { | ||
116 | luaL_setfuncs(L, func, 0); | ||
117 | } | ||
diff --git a/src/term.c b/src/term.c new file mode 100644 index 0000000..2adb1e9 --- /dev/null +++ b/src/term.c | |||
@@ -0,0 +1,37 @@ | |||
1 | /// @submodule system | ||
2 | #include <lua.h> | ||
3 | #include <lauxlib.h> | ||
4 | #include <lualib.h> | ||
5 | #include "compat.h" | ||
6 | |||
7 | #ifndef _MSC_VER | ||
8 | # include <unistd.h> | ||
9 | #endif | ||
10 | |||
11 | |||
12 | /*** | ||
13 | Checks if a file-handle is a TTY. | ||
14 | |||
15 | @function isatty | ||
16 | @tparam file file the file-handle to check | ||
17 | @treturn boolean true if the file is a tty | ||
18 | */ | ||
19 | static int lua_isatty(lua_State* L) { | ||
20 | FILE **fh = (FILE **) luaL_checkudata(L, 1, LUA_FILEHANDLE); | ||
21 | lua_pushboolean(L, isatty(fileno(*fh))); | ||
22 | return 1; | ||
23 | } | ||
24 | |||
25 | |||
26 | |||
27 | static luaL_Reg func[] = { | ||
28 | { "isatty", lua_isatty }, | ||
29 | { NULL, NULL } | ||
30 | }; | ||
31 | |||
32 | /*------------------------------------------------------------------------- | ||
33 | * Initializes module | ||
34 | *-------------------------------------------------------------------------*/ | ||
35 | void term_open(lua_State *L) { | ||
36 | luaL_setfuncs(L, func, 0); | ||
37 | } | ||
@@ -1,3 +1,4 @@ | |||
1 | /// @submodule system | ||
1 | #include <lua.h> | 2 | #include <lua.h> |
2 | #include <lauxlib.h> | 3 | #include <lauxlib.h> |
3 | 4 | ||
@@ -50,11 +51,8 @@ static double time_gettime(void) { | |||
50 | } | 51 | } |
51 | #endif | 52 | #endif |
52 | 53 | ||
53 | /*------------------------------------------------------------------------- | 54 | |
54 | * Gets monotonic time in s | 55 | |
55 | * Returns | ||
56 | * time in s. | ||
57 | *-------------------------------------------------------------------------*/ | ||
58 | #ifdef _WIN32 | 56 | #ifdef _WIN32 |
59 | WINBASEAPI ULONGLONG WINAPI GetTickCount64(VOID); | 57 | WINBASEAPI ULONGLONG WINAPI GetTickCount64(VOID); |
60 | 58 | ||
@@ -70,53 +68,84 @@ static double time_monotime(void) { | |||
70 | } | 68 | } |
71 | #endif | 69 | #endif |
72 | 70 | ||
73 | /*------------------------------------------------------------------------- | 71 | |
74 | * Returns the current system time, 1970 (UTC), in secconds. | 72 | |
75 | *-------------------------------------------------------------------------*/ | 73 | /*** |
74 | Get system time. | ||
75 | The time is returned as the seconds since the epoch (1 January 1970 00:00:00). | ||
76 | @function gettime | ||
77 | @treturn number seconds (fractional) | ||
78 | */ | ||
76 | static int time_lua_gettime(lua_State *L) | 79 | static int time_lua_gettime(lua_State *L) |
77 | { | 80 | { |
78 | lua_pushnumber(L, time_gettime()); | 81 | lua_pushnumber(L, time_gettime()); |
79 | return 1; | 82 | return 1; |
80 | } | 83 | } |
81 | 84 | ||
82 | /*------------------------------------------------------------------------- | 85 | |
83 | * Returns the monotonic time the system has been up, in secconds. | 86 | |
84 | *-------------------------------------------------------------------------*/ | 87 | /*** |
88 | Get monotonic time. | ||
89 | The time is returned as the seconds since system start. | ||
90 | @function monotime | ||
91 | @treturn number seconds (fractional) | ||
92 | */ | ||
85 | static int time_lua_monotime(lua_State *L) | 93 | static int time_lua_monotime(lua_State *L) |
86 | { | 94 | { |
87 | lua_pushnumber(L, time_monotime()); | 95 | lua_pushnumber(L, time_monotime()); |
88 | return 1; | 96 | return 1; |
89 | } | 97 | } |
90 | 98 | ||
91 | /*------------------------------------------------------------------------- | 99 | |
92 | * Sleep for n seconds. | 100 | |
93 | *-------------------------------------------------------------------------*/ | 101 | /*** |
102 | Sleep without a busy loop. | ||
103 | This function will sleep, without doing a busy-loop and wasting CPU cycles. | ||
104 | @function sleep | ||
105 | @tparam number seconds seconds to sleep (fractional). | ||
106 | @tparam[opt=16] integer precision minimum stepsize in milliseconds (Windows only, ignored elsewhere) | ||
107 | @return `true` on success, or `nil+err` on failure | ||
108 | */ | ||
94 | #ifdef _WIN32 | 109 | #ifdef _WIN32 |
95 | static int time_lua_sleep(lua_State *L) | 110 | static int time_lua_sleep(lua_State *L) |
96 | { | 111 | { |
97 | double n = luaL_checknumber(L, 1); | 112 | double n = luaL_checknumber(L, 1); |
98 | if (n < 0.0) n = 0.0; | 113 | |
99 | if (n < DBL_MAX/1000.0) n *= 1000.0; | 114 | int precision = luaL_optinteger(L, 2, 16); |
100 | if (n > INT_MAX) n = INT_MAX; | 115 | if (precision < 0 || precision > 16) precision = 16; |
101 | Sleep((int)n); | 116 | |
102 | return 0; | 117 | if (n > 0.0) { |
118 | if (n < DBL_MAX/1000.0) n *= 1000.0; | ||
119 | if (n > INT_MAX) n = INT_MAX; | ||
120 | if (timeBeginPeriod(precision) != TIMERR_NOERROR) { | ||
121 | lua_pushnil(L); | ||
122 | lua_pushstring(L, "failed to set timer precision"); | ||
123 | return 2; | ||
124 | }; | ||
125 | Sleep((int)n); | ||
126 | timeEndPeriod(precision); | ||
127 | } | ||
128 | lua_pushboolean(L, 1); | ||
129 | return 1; | ||
103 | } | 130 | } |
104 | #else | 131 | #else |
105 | static int time_lua_sleep(lua_State *L) | 132 | static int time_lua_sleep(lua_State *L) |
106 | { | 133 | { |
107 | double n = luaL_checknumber(L, 1); | 134 | double n = luaL_checknumber(L, 1); |
108 | struct timespec t, r; | 135 | struct timespec t, r; |
109 | if (n < 0.0) n = 0.0; | 136 | if (n > 0.0) { |
110 | if (n > INT_MAX) n = INT_MAX; | 137 | if (n > INT_MAX) n = INT_MAX; |
111 | t.tv_sec = (int) n; | 138 | t.tv_sec = (int) n; |
112 | n -= t.tv_sec; | 139 | n -= t.tv_sec; |
113 | t.tv_nsec = (int) (n * 1000000000); | 140 | t.tv_nsec = (int) (n * 1000000000); |
114 | if (t.tv_nsec >= 1000000000) t.tv_nsec = 999999999; | 141 | if (t.tv_nsec >= 1000000000) t.tv_nsec = 999999999; |
115 | while (nanosleep(&t, &r) != 0) { | 142 | while (nanosleep(&t, &r) != 0) { |
116 | t.tv_sec = r.tv_sec; | 143 | t.tv_sec = r.tv_sec; |
117 | t.tv_nsec = r.tv_nsec; | 144 | t.tv_nsec = r.tv_nsec; |
145 | } | ||
118 | } | 146 | } |
119 | return 0; | 147 | lua_pushboolean(L, 1); |
148 | return 1; | ||
120 | } | 149 | } |
121 | #endif | 150 | #endif |
122 | 151 | ||