From 03e9d989f84dafda9b9ce7aa4227db076ef2f479 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 16 Oct 2024 20:26:59 -0700 Subject: [PATCH] make scheduler into a crate feature --- Cargo.toml | 4 ++++ src/lib.rs | 1 + src/runner/runner.rs | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 486ed4c..fde6cc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,10 @@ license = "MIT OR Apache-2.0" description = "Run embedded Luau scripts which manipulate the DOM." authors = ["Rhys Lloyd "] +[features] +default=["run-service"] +run-service=[] + [dependencies] glam = "0.29.0" mlua = { version = "0.10.0-beta", features = ["luau"] } diff --git a/src/lib.rs b/src/lib.rs index 669c126..fd38760 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ pub mod runner; pub mod context; +#[cfg(feature="run-service")] pub(crate) mod scheduler; #[cfg(test)] diff --git a/src/runner/runner.rs b/src/runner/runner.rs index 571a978..39fa25a 100644 --- a/src/runner/runner.rs +++ b/src/runner/runner.rs @@ -1,4 +1,5 @@ use crate::context::Context; +#[cfg(feature="run-service")] use crate::scheduler::scheduler_mut; pub struct Runner{ @@ -30,6 +31,7 @@ fn init(lua:&mlua::Lua)->mlua::Result<()>{ //global environment let globals=lua.globals(); + #[cfg(feature="run-service")] crate::scheduler::set_globals(lua,&globals)?; super::r#enum::set_globals(lua,&globals)?; super::color3::set_globals(lua,&globals)?; @@ -62,6 +64,7 @@ impl Runner{ } //this makes set_app_data shut up about the lifetime self.lua.set_app_data::<&'static mut rbx_dom_weak::WeakDom>(unsafe{core::mem::transmute(&mut context.dom)}); + #[cfg(feature="run-service")] self.lua.set_app_data::(crate::scheduler::Scheduler::default()); Ok(Runnable{ lua:self.lua, @@ -78,6 +81,7 @@ pub struct Runnable<'a>{ impl Runnable<'_>{ pub fn drop_context(self)->Runner{ self.lua.remove_app_data::<&'static mut rbx_dom_weak::WeakDom>(); + #[cfg(feature="run-service")] self.lua.remove_app_data::(); Runner{ lua:self.lua, @@ -95,11 +99,13 @@ impl Runnable<'_>{ // No need to schedule the thread here Ok(()) } + #[cfg(feature="run-service")] pub fn has_scheduled_threads(&self)->Result{ scheduler_mut(&self.lua,|scheduler| Ok(scheduler.has_scheduled_threads()) ) } + #[cfg(feature="run-service")] pub fn game_tick(&self)->Result<(),mlua::Error>{ if let Some(threads)=scheduler_mut(&self.lua,|scheduler|Ok(scheduler.tick_threads()))?{ for thread in threads{