diff --git a/src/lune/builtins/task.rs b/src/lune/builtins/task.rs index b29b502..98a0383 100644 --- a/src/lune/builtins/task.rs +++ b/src/lune/builtins/task.rs @@ -117,7 +117,7 @@ fn coroutine_status<'a>( fn coroutine_resume<'lua>( lua: &'lua Lua, - value: LuaThreadOrTaskReference, + (value, arguments): (LuaThreadOrTaskReference, LuaMultiValue<'lua>), ) -> LuaResult<(bool, LuaMultiValue<'lua>)> { let sched = lua.app_data_ref::<&TaskScheduler>().unwrap(); if sched.current_task().is_none() { @@ -128,10 +128,10 @@ fn coroutine_resume<'lua>( let current = sched.current_task().unwrap(); let result = match value { LuaThreadOrTaskReference::Thread(t) => { - let task = sched.create_task(TaskKind::Instant, t, None, true)?; + let task = sched.create_task(TaskKind::Instant, t, Some(arguments), true)?; sched.resume_task(task, None) } - LuaThreadOrTaskReference::TaskReference(t) => sched.resume_task(t, None), + LuaThreadOrTaskReference::TaskReference(t) => sched.resume_task(t, Some(Ok(arguments))), }; sched.force_set_current_task(Some(current)); match result { diff --git a/tests/globals/coroutine.luau b/tests/globals/coroutine.luau index 5780b78..8db0c42 100644 --- a/tests/globals/coroutine.luau +++ b/tests/globals/coroutine.luau @@ -74,3 +74,13 @@ end)() assert(not flag2, "Wait failed while inside wrap (1)") task.wait(0.2) assert(flag2, "Wait failed while inside wrap (2)") + +-- Coroutines should be passed arguments on initial resume + +local co = coroutine.create(function(a, b, c) + assert(a == 1) + assert(b == "Hello, world!") + assert(c == true) +end) + +coroutine.resume(co, 1, "Hello, world!", true)