diff options
Diffstat (limited to 'system')
-rw-r--r-- | system/init.lua | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/system/init.lua b/system/init.lua index a81978e..28fe65c 100644 --- a/system/init.lua +++ b/system/init.lua | |||
@@ -236,10 +236,10 @@ do | |||
236 | -- Using `system.readansi` is preferred over this function. Since this function can leave stray/invalid | 236 | -- Using `system.readansi` is preferred over this function. Since this function can leave stray/invalid |
237 | -- byte-sequences in the input buffer, while `system.readansi` reads full ANSI and UTF8 sequences. | 237 | -- byte-sequences in the input buffer, while `system.readansi` reads full ANSI and UTF8 sequences. |
238 | -- @tparam number timeout the timeout in seconds. | 238 | -- @tparam number timeout the timeout in seconds. |
239 | -- @tparam[opt=system.sleep] function fsleep the function to call for sleeping. | 239 | -- @tparam[opt=system.sleep] function fsleep the function to call for sleeping; `ok, err = fsleep(secs)` |
240 | -- @treturn[1] byte the byte value that was read. | 240 | -- @treturn[1] byte the byte value that was read. |
241 | -- @treturn[2] nil if no key was read | 241 | -- @treturn[2] nil if no key was read |
242 | -- @treturn[2] string error message; `"timeout"` if the timeout was reached. | 242 | -- @treturn[2] string error message when the timeout was reached (`"timeout"`), or if `sleep` failed. |
243 | function system.readkey(timeout, fsleep) | 243 | function system.readkey(timeout, fsleep) |
244 | if type(timeout) ~= "number" then | 244 | if type(timeout) ~= "number" then |
245 | error("arg #1 to readkey, expected timeout in seconds, got " .. type(timeout), 2) | 245 | error("arg #1 to readkey, expected timeout in seconds, got " .. type(timeout), 2) |
@@ -248,7 +248,10 @@ do | |||
248 | local interval = 0.0125 | 248 | local interval = 0.0125 |
249 | local key = system._readkey() | 249 | local key = system._readkey() |
250 | while key == nil and timeout > 0 do | 250 | while key == nil and timeout > 0 do |
251 | (fsleep or system.sleep)(math.min(interval, timeout)) | 251 | local ok, err = (fsleep or system.sleep)(math.min(interval, timeout)) |
252 | if not ok then | ||
253 | return nil, err | ||
254 | end | ||
252 | timeout = timeout - interval | 255 | timeout = timeout - interval |
253 | interval = math.min(0.2, interval * 2) | 256 | interval = math.min(0.2, interval * 2) |
254 | key = system._readkey() | 257 | key = system._readkey() |