aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorThijs <thijs@thijsschreijer.nl>2025-07-11 13:50:03 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2025-07-11 22:45:08 +0200
commit9b835273c0993a8f67e6c93024099ca99cbf6344 (patch)
treebe15e5ef1d77a324dc96f2515bd1ca9ecdf74a82 /system
parent8d55a6c506cd22fb40bd94fddcc8e82f357f7dff (diff)
downloadluasystem-9b835273c0993a8f67e6c93024099ca99cbf6344.tar.gz
luasystem-9b835273c0993a8f67e6c93024099ca99cbf6344.tar.bz2
luasystem-9b835273c0993a8f67e6c93024099ca99cbf6344.zip
fix(readkey): improve error handling
system.readkey now passes any errors from system._readkey on to the caller.
Diffstat (limited to 'system')
-rw-r--r--system/init.lua14
1 files changed, 9 insertions, 5 deletions
diff --git a/system/init.lua b/system/init.lua
index eeaf38f..9b71d4d 100644
--- a/system/init.lua
+++ b/system/init.lua
@@ -256,19 +256,23 @@ do
256 end 256 end
257 257
258 local interval = 0.0125 258 local interval = 0.0125
259 local key = system._readkey() 259 local ok
260 local key, err = system._readkey()
260 while key == nil and timeout > 0 do 261 while key == nil and timeout > 0 do
261 local ok, err = (fsleep or system.sleep)(math.min(interval, timeout)) 262 if err then
263 return nil, err
264 end
265 ok, err = (fsleep or system.sleep)(math.min(interval, timeout))
262 if not ok then 266 if not ok then
263 return nil, err 267 return nil, err
264 end 268 end
265 timeout = timeout - interval 269 timeout = timeout - interval
266 interval = math.min(0.1, interval * 2) 270 interval = math.min(0.1, interval * 2)
267 key = system._readkey() 271 key, err = system._readkey()
268 end 272 end
269 273
270 if key then 274 if key or err then
271 return key 275 return key, err
272 end 276 end
273 return nil, "timeout" 277 return nil, "timeout"
274 end 278 end