Compare commits
9 Commits
run-servic
...
master
Author | SHA1 | Date | |
---|---|---|---|
3797d226e4 | |||
1e7814488e | |||
fd2aa19949 | |||
24701dc5fe | |||
d7d24cc64c | |||
bd38c6f1e4 | |||
6f0749f827 | |||
a6eb5e184c | |||
210832c737 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -402,7 +402,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "roblox_emulator"
|
||||
version = "0.4.6"
|
||||
version = "0.4.7"
|
||||
dependencies = [
|
||||
"glam",
|
||||
"mlua",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "roblox_emulator"
|
||||
version = "0.4.6"
|
||||
version = "0.4.7"
|
||||
edition = "2021"
|
||||
repository = "https://git.itzana.me/StrafesNET/roblox_emulator"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
@ -96,42 +96,6 @@ impl ScriptConnection{
|
||||
}
|
||||
}
|
||||
|
||||
fn wait_thread(lua:&mlua::Lua,this:ScriptSignal)->Result<(),mlua::Error>{
|
||||
Ok(this.wait(lua.current_thread()))
|
||||
}
|
||||
|
||||
// This is used to avoid calling coroutine.yield from the rust side.
|
||||
const LUA_WAIT:&str=
|
||||
"local coroutine_yield=coroutine.yield
|
||||
local wait_thread=wait_thread
|
||||
return function(signal)
|
||||
wait_thread(signal)
|
||||
return coroutine_yield()
|
||||
end";
|
||||
|
||||
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
||||
let coroutine_table=globals.get::<mlua::Table>("coroutine")?;
|
||||
let wait_thread=lua.create_function(wait_thread)?;
|
||||
|
||||
//create wait function environment
|
||||
let wait_env=lua.create_table()?;
|
||||
wait_env.raw_set("coroutine",coroutine_table)?;
|
||||
wait_env.raw_set("wait_thread",wait_thread)?;
|
||||
|
||||
//construct wait function from Lua code
|
||||
let wait=lua.load(LUA_WAIT)
|
||||
.set_name("wait")
|
||||
.set_environment(wait_env)
|
||||
.call::<mlua::Function>(())?;
|
||||
|
||||
lua.register_userdata_type::<ScriptSignal>(|reg|{
|
||||
reg.add_field("Wait",wait);
|
||||
mlua::UserData::register(reg);
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl mlua::UserData for ScriptSignal{
|
||||
fn add_methods<M:mlua::UserDataMethods<Self>>(methods:&mut M){
|
||||
methods.add_method("Connect",|_lua,this,f:mlua::Function|
|
||||
@ -170,3 +134,39 @@ impl mlua::UserData for ScriptConnection{
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn wait_thread(lua:&mlua::Lua,this:ScriptSignal)->Result<(),mlua::Error>{
|
||||
Ok(this.wait(lua.current_thread()))
|
||||
}
|
||||
|
||||
// This is used to avoid calling coroutine.yield from the rust side.
|
||||
const LUA_WAIT:&str=
|
||||
"local coroutine_yield=coroutine.yield
|
||||
local wait_thread=wait_thread
|
||||
return function(signal)
|
||||
wait_thread(signal)
|
||||
return coroutine_yield()
|
||||
end";
|
||||
|
||||
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
||||
let coroutine_table=globals.get::<mlua::Table>("coroutine")?;
|
||||
let wait_thread=lua.create_function(wait_thread)?;
|
||||
|
||||
//create wait function environment
|
||||
let wait_env=lua.create_table()?;
|
||||
wait_env.raw_set("coroutine",coroutine_table)?;
|
||||
wait_env.raw_set("wait_thread",wait_thread)?;
|
||||
|
||||
//construct wait function from Lua code
|
||||
let wait=lua.load(LUA_WAIT)
|
||||
.set_name("wait")
|
||||
.set_environment(wait_env)
|
||||
.call::<mlua::Function>(())?;
|
||||
|
||||
lua.register_userdata_type::<ScriptSignal>(|reg|{
|
||||
reg.add_field("Wait",wait);
|
||||
mlua::UserData::register(reg);
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user