Compare commits
2 Commits
368ce7da9e
...
f8f659e8ce
Author | SHA1 | Date | |
---|---|---|---|
f8f659e8ce | |||
135103364d |
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[registries.strafesnet]
|
||||||
|
index = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
@ -57,27 +57,33 @@ impl Scheduler{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn coerce_float64(value:&mlua::Value)->Option<f64>{
|
|
||||||
match value{
|
|
||||||
&mlua::Value::Integer(i)=>Some(i as f64),
|
|
||||||
&mlua::Value::Number(f)=>Some(f),
|
|
||||||
_=>None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn scheduler_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut crate::scheduler::Scheduler)->mlua::Result<T>)->mlua::Result<T>{
|
pub fn scheduler_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut crate::scheduler::Scheduler)->mlua::Result<T>)->mlua::Result<T>{
|
||||||
let mut scheduler=lua.app_data_mut::<crate::scheduler::Scheduler>().ok_or(mlua::Error::runtime("Scheduler missing"))?;
|
let mut scheduler=lua.app_data_mut::<crate::scheduler::Scheduler>().ok_or(mlua::Error::runtime("Scheduler missing"))?;
|
||||||
f(&mut *scheduler)
|
f(&mut *scheduler)
|
||||||
}
|
}
|
||||||
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
||||||
let schedule_thread=lua.create_function(move|lua,dt:mlua::Value|{
|
let schedule_thread=lua.create_function(|lua,dt:mlua::Value|{
|
||||||
let delay=coerce_float64(&dt).ok_or(mlua::Error::runtime("Expected float"))?.max(0.0)*60.0;
|
let delay=match dt{
|
||||||
if delay<u64::MAX as f64{
|
mlua::Value::Integer(i)=>i.max(0) as u64*60,
|
||||||
scheduler_mut(lua,|scheduler|{
|
mlua::Value::Number(f)=>{
|
||||||
scheduler.schedule_thread((delay as u64).max(2),lua.current_thread());
|
let delay=f.max(0.0)*60.0;
|
||||||
Ok(())
|
match delay.classify(){
|
||||||
}).unwrap();
|
std::num::FpCategory::Nan=>Err(mlua::Error::runtime("NaN"))?,
|
||||||
}
|
std::num::FpCategory::Infinite=>return Ok(()),
|
||||||
Ok(())
|
std::num::FpCategory::Normal=>if (u64::MAX as f64)<delay{
|
||||||
|
return Ok(());
|
||||||
|
},
|
||||||
|
_=>(),
|
||||||
|
}
|
||||||
|
delay as u64
|
||||||
|
},
|
||||||
|
mlua::Value::Nil=>0,
|
||||||
|
_=>Err(mlua::Error::runtime("Expected float"))?,
|
||||||
|
};
|
||||||
|
scheduler_mut(lua,|scheduler|{
|
||||||
|
scheduler.schedule_thread(delay.max(2),lua.current_thread());
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
})?;
|
})?;
|
||||||
let wait_env=lua.create_table()?;
|
let wait_env=lua.create_table()?;
|
||||||
wait_env.raw_set("coroutine",globals.get::<mlua::Table>("coroutine")?)?;
|
wait_env.raw_set("coroutine",globals.get::<mlua::Table>("coroutine")?)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user