mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Fix coroutine.resume
This commit is contained in:
parent
b1e7b2dd77
commit
8fca650f46
2 changed files with 16 additions and 2 deletions
|
@ -15,6 +15,11 @@ pub fn create(lua: &Lua) -> LuaResult<()> {
|
|||
let coroutine: LuaTable = lua.globals().raw_get("coroutine")?;
|
||||
let close: LuaFunction = coroutine.raw_get("close")?;
|
||||
lua.set_named_registry_value("coroutine.close", close)?;
|
||||
// HACK: coroutine.resume has some weird scheduling issues, but our custom
|
||||
// task.spawn implementation is more or less a replacement for it, so we
|
||||
// overwrite the original coroutine.resume function with it to fix that
|
||||
coroutine.raw_set("resume", lua.create_async_function(task_spawn)?)?;
|
||||
// Rest of the task library is normal, just async functions, no metatable
|
||||
lua.globals().raw_set(
|
||||
"task",
|
||||
TableBuilder::new(lua)?
|
||||
|
|
|
@ -41,6 +41,15 @@ task.spawn(function()
|
|||
task.wait(0.1)
|
||||
flag = true
|
||||
end)
|
||||
assert(not flag, "Wait failed for a task-spawned thread (1)")
|
||||
assert(not flag, "Wait failed while inside task-spawned thread (1)")
|
||||
task.wait(0.2)
|
||||
assert(flag, "Wait failed for a task-spawned thread (2)")
|
||||
assert(flag, "Wait failed while inside task-spawned thread (2)")
|
||||
|
||||
local flag2: boolean = false
|
||||
coroutine.resume(coroutine.create(function()
|
||||
task.wait(0.1)
|
||||
flag2 = true
|
||||
end))
|
||||
assert(not flag2, "Wait failed while inside coroutine (1)")
|
||||
task.wait(0.2)
|
||||
assert(flag2, "Wait failed while inside coroutine (2)")
|
||||
|
|
Loading…
Reference in a new issue