diff --git a/src/lune/mod.rs b/src/lune/mod.rs index 2477893..c625719 100644 --- a/src/lune/mod.rs +++ b/src/lune/mod.rs @@ -44,11 +44,15 @@ impl Lune { let lua = Arc::new(Lua::new()); let sched = Scheduler::new(Arc::clone(&lua)); - let main = lua + let main_fn = lua .load(script_contents.as_ref()) - .set_name(script_name.as_ref()); - sched.push_front(main, ())?; + .set_name(script_name.as_ref()) + .into_function()?; + let main_thread = lua.create_thread(main_fn)?.into_owned(); + sched + .push_back(main_thread, ()) + .expect("Failed to enqueue thread for main"); Ok(sched.run_to_completion().await) } } diff --git a/src/lune/scheduler/impl_async.rs b/src/lune/scheduler/impl_async.rs index b43f0e7..7e1ca67 100644 --- a/src/lune/scheduler/impl_async.rs +++ b/src/lune/scheduler/impl_async.rs @@ -1,7 +1,7 @@ use futures_util::Future; use mlua::prelude::*; -use super::{traits::IntoLuaOwnedThread, SchedulerImpl}; +use super::SchedulerImpl; impl<'lua, 'fut> SchedulerImpl<'fut> where @@ -10,7 +10,7 @@ where /** Schedules a plain future to run whenever the scheduler is available. */ - pub fn schedule_future(&self, fut: F) + pub fn schedule_future(&'lua self, fut: F) where F: 'fut + Future, { @@ -24,15 +24,11 @@ where /** Schedules the given `thread` to run when the given `fut` completes. */ - pub fn schedule_future_thread(&'fut self, thread: T, fut: F) -> LuaResult<()> + pub fn schedule_future_thread(&'lua self, thread: LuaOwnedThread, fut: F) -> LuaResult<()> where - T: IntoLuaOwnedThread, R: IntoLuaMulti<'fut>, F: 'fut + Future>, { - let thread = thread.into_owned_lua_thread(&self.lua)?; - - // FIXME: We use self in the future below, so this doesn't compile... how to fix? self.schedule_future(async move { let rets = fut.await.expect("Failed to receive result"); self.push_back(thread, rets) diff --git a/src/lune/scheduler/impl_runner.rs b/src/lune/scheduler/impl_runner.rs index ff37ca0..878bde7 100644 --- a/src/lune/scheduler/impl_runner.rs +++ b/src/lune/scheduler/impl_runner.rs @@ -4,7 +4,7 @@ use futures_util::StreamExt; use mlua::prelude::*; use tokio::task::LocalSet; -use super::{traits::IntoLuaOwnedThread, SchedulerImpl}; +use super::SchedulerImpl; impl<'lua, 'fut> SchedulerImpl<'fut> where @@ -119,22 +119,4 @@ where ExitCode::SUCCESS } } - - /** - Schedules a new main thread and runs the scheduler until completion. - - See [`Self::run_to_completion`] for more info. - */ - pub async fn run_main( - &'lua self, - main: impl IntoLuaOwnedThread, - args: impl IntoLuaMulti<'lua>, - ) -> ExitCode { - let thread = main - .into_owned_lua_thread(&self.lua) - .expect("Failed to create thread for main"); - self.push_back(thread, args) - .expect("Failed to queue thread for main"); - self.run_to_completion().await - } } diff --git a/src/lune/scheduler/impl_threads.rs b/src/lune/scheduler/impl_threads.rs index da043c0..b7d2b94 100644 --- a/src/lune/scheduler/impl_threads.rs +++ b/src/lune/scheduler/impl_threads.rs @@ -4,7 +4,6 @@ use mlua::prelude::*; use super::{ thread::{SchedulerThread, SchedulerThreadId, SchedulerThreadSender}, - traits::IntoLuaOwnedThread, SchedulerImpl, }; @@ -58,10 +57,9 @@ where */ pub fn push_front( &'lua self, - thread: impl IntoLuaOwnedThread, + thread: LuaOwnedThread, args: impl IntoLuaMulti<'lua>, ) -> LuaResult { - let thread = thread.into_owned_lua_thread(&self.lua)?; let args = args.into_lua_multi(&self.lua)?; let thread = SchedulerThread::new(&self.lua, thread, args)?; @@ -85,10 +83,9 @@ where */ pub fn push_back( &'lua self, - thread: impl IntoLuaOwnedThread, + thread: LuaOwnedThread, args: impl IntoLuaMulti<'lua>, ) -> LuaResult { - let thread = thread.into_owned_lua_thread(&self.lua)?; let args = args.into_lua_multi(&self.lua)?; let thread = SchedulerThread::new(&self.lua, thread, args)?;