Check argument against negative sleep duration

This commit is contained in:
lumi 2025-06-28 19:59:37 +10:00
parent d5e85f2c30
commit 505364a661
Signed by: luaneko
GPG Key ID: 406809B8763FF07A
2 changed files with 6 additions and 1 deletions

View File

@ -36,7 +36,7 @@ impl lb_tasklib {
}
pub async extern "Lua-C" fn sleep(ms: f64) {
sleep(Duration::from_secs_f64(ms / 1000.)).await;
sleep(Duration::from_secs_f64(ms.max(0.) / 1000.)).await;
}
pub extern "Lua" fn spawn(f: function, ...) -> lb_task {

View File

@ -111,6 +111,11 @@ describe("spawn", function()
end)
describe("sleep", function()
test("invalid arg", function()
assert(not pcall(task.sleep, "invalid"))
task.sleep(-1) -- negative sleep should just become 0ms
end)
test("sleep is asynchronous", function()
local value
spawn(function()