make scheduler into a crate feature

This commit is contained in:
Quaternions 2024-10-16 20:26:59 -07:00
parent 5ddb3dacfd
commit 03e9d989f8
3 changed files with 11 additions and 0 deletions

View File

@ -7,6 +7,10 @@ license = "MIT OR Apache-2.0"
description = "Run embedded Luau scripts which manipulate the DOM."
authors = ["Rhys Lloyd <krakow20@gmail.com>"]
[features]
default=["run-service"]
run-service=[]
[dependencies]
glam = "0.29.0"
mlua = { version = "0.10.0-beta", features = ["luau"] }

View File

@ -1,5 +1,6 @@
pub mod runner;
pub mod context;
#[cfg(feature="run-service")]
pub(crate) mod scheduler;
#[cfg(test)]

View File

@ -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>(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::<crate::scheduler::Scheduler>();
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<bool,mlua::Error>{
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{