Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f259022666 | |||
| 52b4b12b43 | |||
| 25577211b2 | |||
| fe91de5668 | |||
| 6dfa46bc67 | |||
| 3ad9d45452 | |||
| 9a03ac199a | |||
| aa1db9551e | |||
| 692697f82b | |||
| 5e45e952d9 | |||
| 09dd442948 | |||
| 726ffeca21 | |||
| 082de122b1 | |||
| bf0c4f74c3 | |||
| 97e2010826 | |||
| de363bc271 | |||
| 849b0813b9 | |||
| fac1f318d7 | |||
| a23e8fc36f | |||
| 58edaf3291 | |||
| d8aacb9ed2 | |||
| 35d60cde16 | |||
| 69d43d8bea | |||
| b2beef4726 |
70
Cargo.lock
generated
70
Cargo.lock
generated
@@ -32,6 +32,12 @@ version = "1.3.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blake3"
|
name = "blake3"
|
||||||
version = "1.5.4"
|
version = "1.5.4"
|
||||||
@@ -121,6 +127,16 @@ dependencies = [
|
|||||||
"windows-targets",
|
"windows-targets",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lock_api"
|
||||||
|
version = "0.4.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"scopeguard",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "luau0-src"
|
name = "luau0-src"
|
||||||
version = "0.10.3+luau640"
|
version = "0.10.3+luau640"
|
||||||
@@ -138,15 +154,15 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mlua"
|
name = "mlua"
|
||||||
version = "0.9.9"
|
version = "0.10.0-beta.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d111deb18a9c9bd33e1541309f4742523bfab01d276bfa9a27519f6de9c11dc7"
|
checksum = "200dd4c8e5f81416d43a023b9921c3cbf01d828094b23a90b26826c3840ba4f3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bstr",
|
"bstr",
|
||||||
"libloading",
|
"libloading",
|
||||||
"mlua-sys",
|
"mlua-sys",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"once_cell",
|
"parking_lot",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -172,10 +188,27 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "parking_lot"
|
||||||
version = "1.19.0"
|
version = "0.12.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot_core"
|
||||||
|
version = "0.9.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall",
|
||||||
|
"smallvec",
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "paste"
|
name = "paste"
|
||||||
@@ -328,7 +361,7 @@ source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
|||||||
checksum = "d7a390c44034fa448c53bd0983dfc2d70d8d6b2f65be4f164d4bec8b6a2a2d09"
|
checksum = "d7a390c44034fa448c53bd0983dfc2d70d8d6b2f65be4f164d4bec8b6a2a2d09"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"bitflags",
|
"bitflags 1.3.2",
|
||||||
"blake3",
|
"blake3",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"rand",
|
"rand",
|
||||||
@@ -336,6 +369,15 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_syscall"
|
||||||
|
version = "0.5.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.6.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rmp"
|
name = "rmp"
|
||||||
version = "0.8.14"
|
version = "0.8.14"
|
||||||
@@ -360,7 +402,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "roblox_emulator"
|
name = "roblox_emulator"
|
||||||
version = "0.4.1"
|
version = "0.4.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glam",
|
"glam",
|
||||||
"mlua",
|
"mlua",
|
||||||
@@ -377,6 +419,12 @@ version = "2.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
|
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.210"
|
version = "1.0.210"
|
||||||
@@ -409,6 +457,12 @@ version = "0.3.11"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
|
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "smallvec"
|
||||||
|
version = "1.13.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.77"
|
version = "2.0.77"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "roblox_emulator"
|
name = "roblox_emulator"
|
||||||
version = "0.4.1"
|
version = "0.4.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
repository = "https://git.itzana.me/StrafesNET/roblox_emulator"
|
repository = "https://git.itzana.me/StrafesNET/roblox_emulator"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
@@ -9,7 +9,7 @@ authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
glam = "0.29.0"
|
glam = "0.29.0"
|
||||||
mlua = { version = "0.9.9", features = ["luau"] }
|
mlua = { version = "0.10.0-beta", features = ["luau"] }
|
||||||
phf = { version = "0.11.2", features = ["macros"] }
|
phf = { version = "0.11.2", features = ["macros"] }
|
||||||
rbx_dom_weak = { version = "2.7.0", registry = "strafesnet" }
|
rbx_dom_weak = { version = "2.7.0", registry = "strafesnet" }
|
||||||
rbx_reflection = { version = "4.7.0", registry = "strafesnet" }
|
rbx_reflection = { version = "4.7.0", registry = "strafesnet" }
|
||||||
|
|||||||
@@ -60,10 +60,19 @@ impl Context{
|
|||||||
|
|
||||||
//insert services
|
//insert services
|
||||||
let game=self.dom.root_ref();
|
let game=self.dom.root_ref();
|
||||||
|
let terrain_bldr=InstanceBuilder::new("Terrain");
|
||||||
let workspace=self.dom.insert(game,
|
let workspace=self.dom.insert(game,
|
||||||
InstanceBuilder::new("Workspace")
|
InstanceBuilder::new("Workspace")
|
||||||
.with_child(InstanceBuilder::new("Terrain"))
|
//Set Workspace.Terrain property equal to Terrain
|
||||||
|
.with_property("Terrain",terrain_bldr.referent())
|
||||||
|
.with_child(terrain_bldr)
|
||||||
);
|
);
|
||||||
|
{
|
||||||
|
//Lowercase and upper case workspace property!
|
||||||
|
let game=self.dom.root_mut();
|
||||||
|
game.properties.insert("workspace".to_owned(),rbx_types::Variant::Ref(workspace));
|
||||||
|
game.properties.insert("Workspace".to_owned(),rbx_types::Variant::Ref(workspace));
|
||||||
|
}
|
||||||
self.dom.insert(game,InstanceBuilder::new("Lighting"));
|
self.dom.insert(game,InstanceBuilder::new("Lighting"));
|
||||||
|
|
||||||
//transfer original root instances into workspace
|
//transfer original root instances into workspace
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ impl From<rbx_types::CFrame> for CFrame{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 cframe_table=lua.create_table()?;
|
let cframe_table=lua.create_table()?;
|
||||||
|
|
||||||
//CFrame.new
|
//CFrame.new
|
||||||
@@ -126,12 +126,12 @@ pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table<'_>)->Result<(),mlua::Err
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl mlua::UserData for CFrame{
|
impl mlua::UserData for CFrame{
|
||||||
fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(fields:&mut F){
|
fn add_fields<F:mlua::UserDataFields<Self>>(fields:&mut F){
|
||||||
//CFrame.p
|
//CFrame.p
|
||||||
fields.add_field_method_get("p",|_,this|Ok(Vector3(this.0.translation)));
|
fields.add_field_method_get("p",|_,this|Ok(Vector3(this.0.translation)));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_methods<'lua,M:mlua::UserDataMethods<'lua,Self>>(methods:&mut M){
|
fn add_methods<M:mlua::UserDataMethods<Self>>(methods:&mut M){
|
||||||
methods.add_method("components",|_,this,()|Ok((
|
methods.add_method("components",|_,this,()|Ok((
|
||||||
this.0.translation.x,
|
this.0.translation.x,
|
||||||
this.0.translation.y,
|
this.0.translation.y,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ impl Into<rbx_types::Color3> for Color3{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 color3_table=lua.create_table()?;
|
let color3_table=lua.create_table()?;
|
||||||
|
|
||||||
color3_table.raw_set("new",
|
color3_table.raw_set("new",
|
||||||
@@ -38,7 +38,7 @@ fn lerp(lhs:f32,rhs:f32,t:f32)->f32{
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl mlua::UserData for Color3{
|
impl mlua::UserData for Color3{
|
||||||
fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(fields:&mut F){
|
fn add_fields<F:mlua::UserDataFields<Self>>(fields:&mut F){
|
||||||
fields.add_field_method_get("r",|_,this|Ok(this.r));
|
fields.add_field_method_get("r",|_,this|Ok(this.r));
|
||||||
fields.add_field_method_set("r",|_,this,val|{
|
fields.add_field_method_set("r",|_,this,val|{
|
||||||
this.r=val;
|
this.r=val;
|
||||||
@@ -55,7 +55,7 @@ impl mlua::UserData for Color3{
|
|||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
fn add_methods<'lua,M:mlua::UserDataMethods<'lua,Self>>(methods:&mut M){
|
fn add_methods<M:mlua::UserDataMethods<Self>>(methods:&mut M){
|
||||||
methods.add_method("Lerp",|_,this,(other,t):(Self,f32)|
|
methods.add_method("Lerp",|_,this,(other,t):(Self,f32)|
|
||||||
Ok(Color3::new(
|
Ok(Color3::new(
|
||||||
lerp(this.r,other.r,t),
|
lerp(this.r,other.r,t),
|
||||||
|
|||||||
31
src/runner/color_sequence.rs
Normal file
31
src/runner/color_sequence.rs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#[derive(Clone,Copy)]
|
||||||
|
pub struct ColorSequence{}
|
||||||
|
impl ColorSequence{
|
||||||
|
pub const fn new()->Self{
|
||||||
|
Self{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Into<rbx_types::ColorSequence> for ColorSequence{
|
||||||
|
fn into(self)->rbx_types::ColorSequence{
|
||||||
|
rbx_types::ColorSequence{
|
||||||
|
keypoints:Vec::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
||||||
|
let number_sequence_table=lua.create_table()?;
|
||||||
|
|
||||||
|
number_sequence_table.raw_set("new",
|
||||||
|
lua.create_function(|_,_:mlua::MultiValue|
|
||||||
|
Ok(ColorSequence::new())
|
||||||
|
)?
|
||||||
|
)?;
|
||||||
|
|
||||||
|
globals.set("ColorSequence",number_sequence_table)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
impl mlua::UserData for ColorSequence{}
|
||||||
|
type_from_lua_userdata!(ColorSequence);
|
||||||
@@ -2,7 +2,9 @@ use mlua::IntoLua;
|
|||||||
|
|
||||||
#[derive(Clone,Copy)]
|
#[derive(Clone,Copy)]
|
||||||
pub struct Enum(u32);
|
pub struct Enum(u32);
|
||||||
|
#[derive(Clone,Copy)]
|
||||||
pub struct EnumItems;
|
pub struct EnumItems;
|
||||||
|
#[derive(Clone,Copy)]
|
||||||
pub struct EnumItem<'a>{
|
pub struct EnumItem<'a>{
|
||||||
ed:&'a rbx_reflection::EnumDescriptor<'a>,
|
ed:&'a rbx_reflection::EnumDescriptor<'a>,
|
||||||
}
|
}
|
||||||
@@ -19,16 +21,16 @@ impl<'a> EnumItem<'a>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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>{
|
||||||
globals.set("Enum",EnumItems)
|
globals.set("Enum",EnumItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl mlua::UserData for EnumItem<'_>{
|
impl mlua::UserData for EnumItem<'_>{
|
||||||
fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(_fields:&mut F){
|
fn add_fields<F:mlua::UserDataFields<Self>>(_fields:&mut F){
|
||||||
}
|
}
|
||||||
fn add_methods<'lua,M:mlua::UserDataMethods<'lua,Self>>(methods:&mut M){
|
fn add_methods<M:mlua::UserDataMethods<Self>>(methods:&mut M){
|
||||||
methods.add_meta_function(mlua::MetaMethod::Index,|lua,(this,val):(EnumItem<'lua>,mlua::String)|{
|
methods.add_meta_function(mlua::MetaMethod::Index,|lua,(this,val):(EnumItem<'_>,mlua::String)|{
|
||||||
match this.ed.items.get(val.to_str()?){
|
match this.ed.items.get(&*val.to_str()?){
|
||||||
Some(&id)=>Enum(id).into_lua(lua),
|
Some(&id)=>Enum(id).into_lua(lua),
|
||||||
None=>mlua::Value::Nil.into_lua(lua),
|
None=>mlua::Value::Nil.into_lua(lua),
|
||||||
}
|
}
|
||||||
@@ -38,12 +40,12 @@ impl mlua::UserData for EnumItem<'_>{
|
|||||||
type_from_lua_userdata_lua_lifetime!(EnumItem);
|
type_from_lua_userdata_lua_lifetime!(EnumItem);
|
||||||
|
|
||||||
impl mlua::UserData for EnumItems{
|
impl mlua::UserData for EnumItems{
|
||||||
fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(_fields:&mut F){
|
fn add_fields<F:mlua::UserDataFields<Self>>(_fields:&mut F){
|
||||||
}
|
}
|
||||||
fn add_methods<'lua,M:mlua::UserDataMethods<'lua,Self>>(methods:&mut M){
|
fn add_methods<M:mlua::UserDataMethods<Self>>(methods:&mut M){
|
||||||
methods.add_meta_function(mlua::MetaMethod::Index,|lua,(_,val):(Self,mlua::String)|{
|
methods.add_meta_function(mlua::MetaMethod::Index,|lua,(_,val):(Self,mlua::String)|{
|
||||||
let db=rbx_reflection_database::get();
|
let db=rbx_reflection_database::get();
|
||||||
match db.enums.get(val.to_str()?){
|
match db.enums.get(&*val.to_str()?){
|
||||||
Some(ed)=>EnumItem::new(ed).into_lua(lua),
|
Some(ed)=>EnumItem::new(ed).into_lua(lua),
|
||||||
None=>mlua::Value::Nil.into_lua(lua),
|
None=>mlua::Value::Nil.into_lua(lua),
|
||||||
}
|
}
|
||||||
@@ -53,9 +55,9 @@ impl mlua::UserData for EnumItems{
|
|||||||
type_from_lua_userdata!(EnumItems);
|
type_from_lua_userdata!(EnumItems);
|
||||||
|
|
||||||
impl mlua::UserData for Enum{
|
impl mlua::UserData for Enum{
|
||||||
fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(_fields:&mut F){
|
fn add_fields<F:mlua::UserDataFields<Self>>(_fields:&mut F){
|
||||||
}
|
}
|
||||||
fn add_methods<'lua,M:mlua::UserDataMethods<'lua,Self>>(_methods:&mut M){
|
fn add_methods<M:mlua::UserDataMethods<Self>>(_methods:&mut M){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
type_from_lua_userdata!(Enum);
|
type_from_lua_userdata!(Enum);
|
||||||
|
|||||||
@@ -1,42 +1,21 @@
|
|||||||
use std::collections::{hash_map::Entry,HashMap};
|
use std::collections::{hash_map::Entry,HashMap};
|
||||||
|
|
||||||
use mlua::{IntoLua,IntoLuaMulti};
|
use mlua::{FromLua,FromLuaMulti,IntoLua,IntoLuaMulti};
|
||||||
use rbx_types::Ref;
|
use rbx_types::Ref;
|
||||||
use rbx_dom_weak::{InstanceBuilder,WeakDom};
|
use rbx_dom_weak::{InstanceBuilder,WeakDom};
|
||||||
|
|
||||||
use super::vector3::Vector3;
|
use super::vector3::Vector3;
|
||||||
|
|
||||||
/// A store of created functions for each Roblox class.
|
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
||||||
/// Functions are created the first time they are accessed and stored in this data structure.
|
|
||||||
#[derive(Default)]
|
|
||||||
struct ClassFunctions<'a>{
|
|
||||||
classes:HashMap<&'static str,//ClassName
|
|
||||||
HashMap<&'static str,//Function name
|
|
||||||
mlua::Function<'a>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
}
|
|
||||||
|
|
||||||
fn place_id<'lua>(lua:&'lua mlua::Lua,tuple:mlua::MultiValue<'lua>)->mlua::Result<mlua::MultiValue<'lua>>{
|
|
||||||
0.into_lua_multi(lua)
|
|
||||||
}
|
|
||||||
type FPointer=for<'lua> fn(&'lua mlua::Lua,mlua::MultiValue<'lua>)->mlua::Result<mlua::MultiValue<'lua>>;
|
|
||||||
static CLASS_FUNCTION_DATABASE:phf::Map<&str,phf::Map<&str,FPointer>>=phf::phf_map!{
|
|
||||||
"DataModel"=>phf::phf_map!{
|
|
||||||
"GetService"=>place_id as FPointer,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table<'_>)->Result<(),mlua::Error>{
|
|
||||||
//class functions store
|
//class functions store
|
||||||
lua.set_app_data::<ClassFunctions<'static>>(ClassFunctions::default());
|
lua.set_app_data(ClassFunctions::default());
|
||||||
|
|
||||||
let instance_table=lua.create_table()?;
|
let instance_table=lua.create_table()?;
|
||||||
|
|
||||||
//Instance.new
|
//Instance.new
|
||||||
instance_table.raw_set("new",
|
instance_table.raw_set("new",
|
||||||
lua.create_function(|lua,(class_name,parent):(mlua::String,Option<Instance>)|{
|
lua.create_function(|lua,(class_name,parent):(mlua::String,Option<Instance>)|{
|
||||||
let class_name_str=class_name.to_str()?;
|
let class_name_str=&*class_name.to_str()?;
|
||||||
let parent=parent.ok_or(mlua::Error::runtime("Nil Parent not yet supported"))?;
|
let parent=parent.ok_or(mlua::Error::runtime("Nil Parent not yet supported"))?;
|
||||||
dom_mut(lua,|dom|{
|
dom_mut(lua,|dom|{
|
||||||
//TODO: Nil instances
|
//TODO: Nil instances
|
||||||
@@ -55,9 +34,9 @@ fn dom_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut WeakDom)->mlua::Result<T>)->m
|
|||||||
let mut dom=lua.app_data_mut::<&'static mut WeakDom>().ok_or(mlua::Error::runtime("DataModel missing"))?;
|
let mut dom=lua.app_data_mut::<&'static mut WeakDom>().ok_or(mlua::Error::runtime("DataModel missing"))?;
|
||||||
f(&mut *dom)
|
f(&mut *dom)
|
||||||
}
|
}
|
||||||
fn class_functions_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut ClassFunctions<'_>)->mlua::Result<T>)->mlua::Result<T>{
|
fn class_functions_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut ClassFunctions)->mlua::Result<T>)->mlua::Result<T>{
|
||||||
let mut dom=lua.app_data_mut::<ClassFunctions<'static>>().ok_or(mlua::Error::runtime("ClassFunctions missing"))?;
|
let mut cf=lua.app_data_mut::<ClassFunctions>().ok_or(mlua::Error::runtime("ClassFunctions missing"))?;
|
||||||
f(&mut *dom)
|
f(&mut *cf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn coerce_float32(value:&mlua::Value)->Option<f32>{
|
fn coerce_float32(value:&mlua::Value)->Option<f32>{
|
||||||
@@ -141,7 +120,7 @@ impl<'a> Iterator for SuperClassIter<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl mlua::UserData for Instance{
|
impl mlua::UserData for Instance{
|
||||||
fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(fields:&mut F){
|
fn add_fields<F:mlua::UserDataFields<Self>>(fields:&mut F){
|
||||||
fields.add_field_method_get("Parent",|lua,this|{
|
fields.add_field_method_get("Parent",|lua,this|{
|
||||||
dom_mut(lua,|dom|{
|
dom_mut(lua,|dom|{
|
||||||
let instance=this.get(dom)?;
|
let instance=this.get(dom)?;
|
||||||
@@ -176,7 +155,7 @@ impl mlua::UserData for Instance{
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
fn add_methods<'lua,M:mlua::UserDataMethods<'lua,Self>>(methods:&mut M){
|
fn add_methods<M:mlua::UserDataMethods<Self>>(methods:&mut M){
|
||||||
methods.add_method("GetChildren",|lua,this,_:()|
|
methods.add_method("GetChildren",|lua,this,_:()|
|
||||||
dom_mut(lua,|dom|{
|
dom_mut(lua,|dom|{
|
||||||
let instance=this.get(dom)?;
|
let instance=this.get(dom)?;
|
||||||
@@ -189,8 +168,8 @@ impl mlua::UserData for Instance{
|
|||||||
Ok(children)
|
Ok(children)
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
let ffc=|lua,this:&Self,(name,search_descendants):(mlua::String,Option<bool>)|{
|
fn ffc(lua:&mlua::Lua,this:&Instance,(name,search_descendants):(mlua::String,Option<bool>))->mlua::Result<Option<Instance>>{
|
||||||
let name_str=name.to_str()?;
|
let name_str=&*name.to_str()?;
|
||||||
dom_mut(lua,|dom|{
|
dom_mut(lua,|dom|{
|
||||||
let instance=this.get(dom)?;
|
let instance=this.get(dom)?;
|
||||||
Ok(
|
Ok(
|
||||||
@@ -203,11 +182,11 @@ impl mlua::UserData for Instance{
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
};
|
}
|
||||||
methods.add_method("FindFirstChild",ffc);
|
methods.add_method("FindFirstChild",ffc);
|
||||||
methods.add_method("WaitForChild",ffc);
|
methods.add_method("WaitForChild",ffc);
|
||||||
methods.add_method("FindFirstChildOfClass",|lua,this,(class,search_descendants):(mlua::String,Option<bool>)|{
|
methods.add_method("FindFirstChildOfClass",|lua,this,(class,search_descendants):(mlua::String,Option<bool>)|{
|
||||||
let class_str=class.to_str()?;
|
let class_str=&*class.to_str()?;
|
||||||
dom_mut(lua,|dom|{
|
dom_mut(lua,|dom|{
|
||||||
Ok(
|
Ok(
|
||||||
match search_descendants.unwrap_or(false){
|
match search_descendants.unwrap_or(false){
|
||||||
@@ -234,7 +213,7 @@ impl mlua::UserData for Instance{
|
|||||||
methods.add_method("IsA",|lua,this,classname:mlua::String|
|
methods.add_method("IsA",|lua,this,classname:mlua::String|
|
||||||
dom_mut(lua,|dom|{
|
dom_mut(lua,|dom|{
|
||||||
let instance=this.get(dom)?;
|
let instance=this.get(dom)?;
|
||||||
Ok(crate::context::class_is_a(instance.class.as_str(),classname.to_str()?))
|
Ok(crate::context::class_is_a(instance.class.as_str(),&*classname.to_str()?))
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
methods.add_method("Destroy",|lua,this,()|
|
methods.add_method("Destroy",|lua,this,()|
|
||||||
@@ -243,79 +222,70 @@ impl mlua::UserData for Instance{
|
|||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
methods.add_meta_function(mlua::MetaMethod::Index,|lua,(this,index):(Instance,mlua::String)|{
|
methods.add_meta_function(mlua::MetaMethod::ToString,|lua,this:Instance|{
|
||||||
let index_str=index.to_str()?;
|
|
||||||
dom_mut(lua,|dom|{
|
dom_mut(lua,|dom|{
|
||||||
let instance=this.get(dom)?;
|
let instance=this.get(dom)?;
|
||||||
|
Ok(instance.name.clone())
|
||||||
|
})
|
||||||
|
});
|
||||||
|
methods.add_meta_function(mlua::MetaMethod::Index,|lua,(this,index):(Instance,mlua::String)|{
|
||||||
|
let index_str=&*index.to_str()?;
|
||||||
|
dom_mut(lua,|dom|{
|
||||||
|
let instance=this.get(dom)?;
|
||||||
|
//println!("__index t={} i={index:?}",instance.name);
|
||||||
|
let db=rbx_reflection_database::get();
|
||||||
|
let class=db.classes.get(instance.class.as_str()).ok_or(mlua::Error::runtime("Class missing"))?;
|
||||||
//Find existing property
|
//Find existing property
|
||||||
match instance.properties.get(index_str)
|
match instance.properties.get(index_str)
|
||||||
|
.cloned()
|
||||||
//Find default value
|
//Find default value
|
||||||
|
.or_else(||db.find_default_property(class,index_str).cloned())
|
||||||
|
//Find virtual property
|
||||||
.or_else(||{
|
.or_else(||{
|
||||||
let db=rbx_reflection_database::get();
|
SuperClassIter{
|
||||||
db.classes.get(instance.class.as_str()).and_then(|cd|
|
database:db,
|
||||||
db.find_default_property(cd,index_str)
|
descriptor:Some(class),
|
||||||
|
}
|
||||||
|
.find_map(|class|
|
||||||
|
find_virtual_property(&instance.properties,class,index_str)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
Some(&rbx_types::Variant::CFrame(cf))=>return Ok(Into::<super::cframe::CFrame>::into(cf).into_lua(lua)),
|
Some(rbx_types::Variant::Int32(val))=>return val.into_lua(lua),
|
||||||
Some(&rbx_types::Variant::Vector3(v))=>return Ok(Into::<super::vector3::Vector3>::into(v).into_lua(lua)),
|
Some(rbx_types::Variant::Int64(val))=>return val.into_lua(lua),
|
||||||
_=>(),
|
Some(rbx_types::Variant::Float32(val))=>return val.into_lua(lua),
|
||||||
|
Some(rbx_types::Variant::Float64(val))=>return val.into_lua(lua),
|
||||||
|
Some(rbx_types::Variant::Ref(val))=>return Instance::new(val).into_lua(lua),
|
||||||
|
Some(rbx_types::Variant::CFrame(cf))=>return Into::<super::cframe::CFrame>::into(cf).into_lua(lua),
|
||||||
|
Some(rbx_types::Variant::Vector3(v))=>return Into::<super::vector3::Vector3>::into(v).into_lua(lua),
|
||||||
|
None=>(),
|
||||||
|
other=>return Err(mlua::Error::runtime(format!("Instance.__index Unsupported property type instance={} index={index_str} value={other:?}",instance.name))),
|
||||||
}
|
}
|
||||||
//find a function with a matching name
|
//find a function with a matching name
|
||||||
if let Some(ret)=class_functions_mut(lua,|cf|{
|
if let Some(function)=class_functions_mut(lua,|cf|{
|
||||||
let class_str=instance.class.as_str();
|
let mut iter=SuperClassIter{
|
||||||
let f=match CLASS_FUNCTION_DATABASE.get_entry(class_str){
|
database:db,
|
||||||
Some((&static_class_str,class_functions))=>{
|
descriptor:Some(class),
|
||||||
match cf.classes.entry(static_class_str){
|
|
||||||
Entry::Occupied(mut occupied_entry)=>{
|
|
||||||
match class_functions.get_entry(index_str){
|
|
||||||
Some((&static_index_str,function_pointer))=>{
|
|
||||||
match occupied_entry.get_mut().entry(static_index_str){
|
|
||||||
Entry::Occupied(occupied_entry)=>{
|
|
||||||
Some(occupied_entry.get().clone())
|
|
||||||
},
|
|
||||||
Entry::Vacant(vacant_entry)=>{
|
|
||||||
Some(vacant_entry.insert(unsafe{core::mem::transmute(lua.create_function(function_pointer)?)}).clone())
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None=>None,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Entry::Vacant(vacant_entry)=>{
|
|
||||||
match class_functions.get_entry(index_str){
|
|
||||||
Some((&static_index_str,function_pointer))=>{
|
|
||||||
let mut h=HashMap::new();
|
|
||||||
h.entry(static_index_str).or_insert(unsafe{core::mem::transmute(lua.create_function(function_pointer)?)});
|
|
||||||
vacant_entry.insert(h).get(static_index_str).map(|f|f.clone())
|
|
||||||
},
|
|
||||||
None=>None,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None=>None,
|
|
||||||
};
|
};
|
||||||
Ok(f.map(|f|{
|
iter.find_map(|class|{
|
||||||
let f_static:mlua::Function::<'static>=unsafe{core::mem::transmute(f)};
|
let mut class_methods=cf.get_or_create_class_methods(&class.name)?;
|
||||||
f_static
|
class_methods.get_or_create_function(lua,index_str)
|
||||||
}))
|
.transpose()
|
||||||
|
}).transpose()
|
||||||
})?{
|
})?{
|
||||||
return Ok(ret.into_lua(lua));
|
return function.into_lua(lua);
|
||||||
}
|
}
|
||||||
//find a child with a matching name
|
//find a child with a matching name
|
||||||
Ok(
|
find_first_child(dom,instance,index_str)
|
||||||
find_first_child(dom,instance,index_str)
|
.map(|instance|Instance::new(instance.referent()))
|
||||||
.map(|instance|Instance::new(instance.referent()))
|
.into_lua(lua)
|
||||||
.into_lua(lua)
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
methods.add_meta_function(mlua::MetaMethod::NewIndex,|lua,(this,index,value):(Instance,mlua::String,mlua::Value)|{
|
methods.add_meta_function(mlua::MetaMethod::NewIndex,|lua,(this,index,value):(Instance,mlua::String,mlua::Value)|{
|
||||||
dom_mut(lua,|dom|{
|
dom_mut(lua,|dom|{
|
||||||
let instance=this.get_mut(dom)?;
|
let instance=this.get_mut(dom)?;
|
||||||
//println!("__newindex t={} i={index:?} v={value:?}",instance.name);
|
//println!("__newindex t={} i={index:?} v={value:?}",instance.name);
|
||||||
let index_str=index.to_str()?;
|
let index_str=&*index.to_str()?;
|
||||||
let db=rbx_reflection_database::get();
|
let db=rbx_reflection_database::get();
|
||||||
let class=db.classes.get(instance.class.as_str()).ok_or(mlua::Error::runtime("Class missing"))?;
|
let class=db.classes.get(instance.class.as_str()).ok_or(mlua::Error::runtime("Class missing"))?;
|
||||||
let mut iter=SuperClassIter{
|
let mut iter=SuperClassIter{
|
||||||
@@ -325,7 +295,7 @@ impl mlua::UserData for Instance{
|
|||||||
let property=iter.find_map(|cls|cls.properties.get(index_str)).ok_or(mlua::Error::runtime(format!("Property '{index_str}' missing on class '{}'",class.name)))?;
|
let property=iter.find_map(|cls|cls.properties.get(index_str)).ok_or(mlua::Error::runtime(format!("Property '{index_str}' missing on class '{}'",class.name)))?;
|
||||||
match &property.data_type{
|
match &property.data_type{
|
||||||
rbx_reflection::DataType::Value(rbx_types::VariantType::Vector3)=>{
|
rbx_reflection::DataType::Value(rbx_types::VariantType::Vector3)=>{
|
||||||
let typed_value:Vector3=value.as_userdata().ok_or(mlua::Error::runtime("Expected Userdata"))?.take()?;
|
let typed_value:Vector3=*value.as_userdata().ok_or(mlua::Error::runtime("Expected Userdata"))?.borrow()?;
|
||||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Vector3(typed_value.into()));
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Vector3(typed_value.into()));
|
||||||
},
|
},
|
||||||
rbx_reflection::DataType::Value(rbx_types::VariantType::Float32)=>{
|
rbx_reflection::DataType::Value(rbx_types::VariantType::Float32)=>{
|
||||||
@@ -338,10 +308,10 @@ impl mlua::UserData for Instance{
|
|||||||
&mlua::Value::Number(num)=>Ok(rbx_types::Enum::from_u32(num as u32)),
|
&mlua::Value::Number(num)=>Ok(rbx_types::Enum::from_u32(num as u32)),
|
||||||
mlua::Value::String(s)=>{
|
mlua::Value::String(s)=>{
|
||||||
let e=db.enums.get(enum_name).ok_or(mlua::Error::runtime("Database DataType Enum name does not exist"))?;
|
let e=db.enums.get(enum_name).ok_or(mlua::Error::runtime("Database DataType Enum name does not exist"))?;
|
||||||
Ok(rbx_types::Enum::from_u32(*e.items.get(s.to_str()?).ok_or(mlua::Error::runtime("Invalid enum item"))?))
|
Ok(rbx_types::Enum::from_u32(*e.items.get(&*s.to_str()?).ok_or(mlua::Error::runtime("Invalid enum item"))?))
|
||||||
},
|
},
|
||||||
mlua::Value::UserData(any_user_data)=>{
|
mlua::Value::UserData(any_user_data)=>{
|
||||||
let e:super::r#enum::Enum=any_user_data.take()?;
|
let e:super::r#enum::Enum=*any_user_data.borrow()?;
|
||||||
Ok(e.into())
|
Ok(e.into())
|
||||||
},
|
},
|
||||||
_=>Err(mlua::Error::runtime("Expected Enum")),
|
_=>Err(mlua::Error::runtime("Expected Enum")),
|
||||||
@@ -349,7 +319,7 @@ impl mlua::UserData for Instance{
|
|||||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Enum(typed_value));
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Enum(typed_value));
|
||||||
},
|
},
|
||||||
rbx_reflection::DataType::Value(rbx_types::VariantType::Color3)=>{
|
rbx_reflection::DataType::Value(rbx_types::VariantType::Color3)=>{
|
||||||
let typed_value:super::color3::Color3=value.as_userdata().ok_or(mlua::Error::runtime("Expected Color3"))?.take()?;
|
let typed_value:super::color3::Color3=*value.as_userdata().ok_or(mlua::Error::runtime("Expected Color3"))?.borrow()?;
|
||||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Color3(typed_value.into()));
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Color3(typed_value.into()));
|
||||||
},
|
},
|
||||||
rbx_reflection::DataType::Value(rbx_types::VariantType::Bool)=>{
|
rbx_reflection::DataType::Value(rbx_types::VariantType::Bool)=>{
|
||||||
@@ -360,6 +330,14 @@ impl mlua::UserData for Instance{
|
|||||||
let typed_value=value.as_str().ok_or(mlua::Error::runtime("Expected boolean"))?;
|
let typed_value=value.as_str().ok_or(mlua::Error::runtime("Expected boolean"))?;
|
||||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::String(typed_value.to_owned()));
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::String(typed_value.to_owned()));
|
||||||
},
|
},
|
||||||
|
rbx_reflection::DataType::Value(rbx_types::VariantType::NumberSequence)=>{
|
||||||
|
let typed_value:super::number_sequence::NumberSequence=*value.as_userdata().ok_or(mlua::Error::runtime("Expected NumberSequence"))?.borrow()?;
|
||||||
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::NumberSequence(typed_value.into()));
|
||||||
|
},
|
||||||
|
rbx_reflection::DataType::Value(rbx_types::VariantType::ColorSequence)=>{
|
||||||
|
let typed_value:super::color_sequence::ColorSequence=*value.as_userdata().ok_or(mlua::Error::runtime("Expected ColorSequence"))?.borrow()?;
|
||||||
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::ColorSequence(typed_value.into()));
|
||||||
|
},
|
||||||
other=>return Err(mlua::Error::runtime(format!("Unimplemented property type: {other:?}"))),
|
other=>return Err(mlua::Error::runtime(format!("Unimplemented property type: {other:?}"))),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -367,3 +345,139 @@ impl mlua::UserData for Instance{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A class function definition shorthand.
|
||||||
|
macro_rules! cf{
|
||||||
|
($f:expr)=>{
|
||||||
|
|lua,mut args|{
|
||||||
|
let this=Instance::from_lua(args.pop_front().unwrap_or(mlua::Value::Nil),lua)?;
|
||||||
|
$f(lua,this,FromLuaMulti::from_lua_multi(args,lua)?)?.into_lua_multi(lua)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
type ClassFunctionPointer=fn(&mlua::Lua,mlua::MultiValue)->mlua::Result<mlua::MultiValue>;
|
||||||
|
// TODO: use macros to define these with better organization
|
||||||
|
/// A double hash map of function pointers.
|
||||||
|
/// The class tree is walked by the Instance.__index metamethod to find available class methods.
|
||||||
|
type CFD=phf::Map<&'static str,// Class name
|
||||||
|
phf::Map<&'static str,// Method name
|
||||||
|
ClassFunctionPointer
|
||||||
|
>
|
||||||
|
>;
|
||||||
|
static CLASS_FUNCTION_DATABASE:CFD=phf::phf_map!{
|
||||||
|
"DataModel"=>phf::phf_map!{
|
||||||
|
"GetService"=>cf!(|lua,_this,service:mlua::String|{
|
||||||
|
dom_mut(lua,|dom|{
|
||||||
|
//dom.root_ref()==this.referent ?
|
||||||
|
match &*service.to_str()?{
|
||||||
|
"Lighting"=>{
|
||||||
|
let referent=find_first_child_of_class(dom,dom.root(),"Lighting")
|
||||||
|
.map(|instance|instance.referent())
|
||||||
|
.unwrap_or_else(||
|
||||||
|
dom.insert(dom.root_ref(),InstanceBuilder::new("Lighting"))
|
||||||
|
);
|
||||||
|
Ok(Instance::new(referent))
|
||||||
|
},
|
||||||
|
other=>Err::<Instance,_>(mlua::Error::runtime(format!("Service '{other}' not supported"))),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
"Terrain"=>phf::phf_map!{
|
||||||
|
"FillBlock"=>cf!(|_lua,_,_:(super::cframe::CFrame,Vector3,super::r#enum::Enum)|mlua::Result::Ok(()))
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A store of created functions for each Roblox class.
|
||||||
|
/// Functions are created the first time they are accessed and stored in this data structure.
|
||||||
|
#[derive(Default)]
|
||||||
|
struct ClassFunctions{
|
||||||
|
classes:HashMap<&'static str,//ClassName
|
||||||
|
HashMap<&'static str,//Method name
|
||||||
|
mlua::Function
|
||||||
|
>
|
||||||
|
>
|
||||||
|
}
|
||||||
|
impl ClassFunctions{
|
||||||
|
/// return self.classes[class] or create the ClassMethods and then return it
|
||||||
|
fn get_or_create_class_methods(&mut self,class:&str)->Option<ClassMethods>{
|
||||||
|
// Use get_entry to get the &'static str keys of the database
|
||||||
|
// and use it as a key for the classes hashmap
|
||||||
|
CLASS_FUNCTION_DATABASE.get_entry(class)
|
||||||
|
.map(|(&static_class_str,method_pointers)|
|
||||||
|
ClassMethods{
|
||||||
|
method_pointers,
|
||||||
|
methods:self.classes.entry(static_class_str)
|
||||||
|
.or_insert_with(||HashMap::new()),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
struct ClassMethods<'a>{
|
||||||
|
method_pointers:&'static phf::Map<&'static str,ClassFunctionPointer>,
|
||||||
|
methods:&'a mut HashMap<&'static str,mlua::Function>,
|
||||||
|
}
|
||||||
|
impl ClassMethods<'_>{
|
||||||
|
/// return self.methods[index] or create the function in the hashmap and then return it
|
||||||
|
fn get_or_create_function(&mut self,lua:&mlua::Lua,index:&str)->mlua::Result<Option<mlua::Function>>{
|
||||||
|
Ok(match self.method_pointers.get_entry(index){
|
||||||
|
Some((&static_index_str,&function_pointer))=>Some(
|
||||||
|
match self.methods.entry(static_index_str){
|
||||||
|
Entry::Occupied(entry)=>entry.get().clone(),
|
||||||
|
Entry::Vacant(entry)=>entry.insert(
|
||||||
|
lua.create_function(function_pointer)?
|
||||||
|
).clone(),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
None=>None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A virtual property pointer definition shorthand.
|
||||||
|
type VirtualPropertyFunctionPointer=fn(&rbx_types::Variant)->Option<rbx_types::Variant>;
|
||||||
|
const fn vpp(
|
||||||
|
property:&'static str,
|
||||||
|
pointer:VirtualPropertyFunctionPointer,
|
||||||
|
)->VirtualProperty{
|
||||||
|
VirtualProperty{
|
||||||
|
property,
|
||||||
|
pointer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
struct VirtualProperty{
|
||||||
|
property:&'static str,// Source property name
|
||||||
|
pointer:VirtualPropertyFunctionPointer,
|
||||||
|
}
|
||||||
|
type VPD=phf::Map<&'static str,// Class name
|
||||||
|
phf::Map<&'static str,// Virtual property name
|
||||||
|
VirtualProperty
|
||||||
|
>
|
||||||
|
>;
|
||||||
|
static VIRTUAL_PROPERTY_DATABASE:VPD=phf::phf_map!{
|
||||||
|
"BasePart"=>phf::phf_map!{
|
||||||
|
"Position"=>vpp("CFrame",|c:&rbx_types::Variant|{
|
||||||
|
let c=match c{
|
||||||
|
rbx_types::Variant::CFrame(c)=>c,
|
||||||
|
_=>return None,//fail silently and ungracefully
|
||||||
|
};
|
||||||
|
Some(rbx_types::Variant::Vector3(c.position))
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
fn find_virtual_property(
|
||||||
|
properties:&HashMap<String,rbx_types::Variant>,
|
||||||
|
class:&rbx_reflection::ClassDescriptor,
|
||||||
|
index:&str
|
||||||
|
)->Option<rbx_types::Variant>{
|
||||||
|
//Find virtual property
|
||||||
|
let class_virtual_properties=VIRTUAL_PROPERTY_DATABASE.get(&class.name)?;
|
||||||
|
let virtual_property=class_virtual_properties.get(index)?;
|
||||||
|
|
||||||
|
//Get source property
|
||||||
|
let variant=properties.get(virtual_property.property)?;
|
||||||
|
|
||||||
|
//Transform Source property with provided function
|
||||||
|
(virtual_property.pointer)(variant)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
macro_rules! type_from_lua_userdata{
|
macro_rules! type_from_lua_userdata{
|
||||||
($asd:ident)=>{
|
($asd:ident)=>{
|
||||||
impl<'lua> mlua::FromLua<'lua> for $asd{
|
impl mlua::FromLua for $asd{
|
||||||
fn from_lua(value:mlua::Value<'lua>,_lua:&'lua mlua::Lua)->Result<Self,mlua::Error>{
|
fn from_lua(value:mlua::Value,_lua:&mlua::Lua)->Result<Self,mlua::Error>{
|
||||||
match value{
|
match value{
|
||||||
mlua::Value::UserData(ud)=>ud.take(),
|
mlua::Value::UserData(ud)=>Ok(*ud.borrow::<Self>()?),
|
||||||
other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))),
|
other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,10 +12,10 @@ macro_rules! type_from_lua_userdata{
|
|||||||
}
|
}
|
||||||
macro_rules! type_from_lua_userdata_lua_lifetime{
|
macro_rules! type_from_lua_userdata_lua_lifetime{
|
||||||
($asd:ident)=>{
|
($asd:ident)=>{
|
||||||
impl<'lua> mlua::FromLua<'lua> for $asd<'lua>{
|
impl mlua::FromLua for $asd<'static>{
|
||||||
fn from_lua(value:mlua::Value<'lua>,_lua:&'lua mlua::Lua)->Result<Self,mlua::Error>{
|
fn from_lua(value:mlua::Value,_lua:&mlua::Lua)->Result<Self,mlua::Error>{
|
||||||
match value{
|
match value{
|
||||||
mlua::Value::UserData(ud)=>ud.take(),
|
mlua::Value::UserData(ud)=>Ok(*ud.borrow::<Self>()?),
|
||||||
other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))),
|
other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ mod color3;
|
|||||||
mod cframe;
|
mod cframe;
|
||||||
mod vector3;
|
mod vector3;
|
||||||
pub mod instance;
|
pub mod instance;
|
||||||
|
mod number_sequence;
|
||||||
|
mod color_sequence;
|
||||||
|
|
||||||
pub use runner::{Runner,Error};
|
pub use runner::{Runner,Error};
|
||||||
|
|||||||
31
src/runner/number_sequence.rs
Normal file
31
src/runner/number_sequence.rs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#[derive(Clone,Copy)]
|
||||||
|
pub struct NumberSequence{}
|
||||||
|
impl NumberSequence{
|
||||||
|
pub const fn new()->Self{
|
||||||
|
Self{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Into<rbx_types::NumberSequence> for NumberSequence{
|
||||||
|
fn into(self)->rbx_types::NumberSequence{
|
||||||
|
rbx_types::NumberSequence{
|
||||||
|
keypoints:Vec::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
||||||
|
let number_sequence_table=lua.create_table()?;
|
||||||
|
|
||||||
|
number_sequence_table.raw_set("new",
|
||||||
|
lua.create_function(|_,_:mlua::MultiValue|
|
||||||
|
Ok(NumberSequence::new())
|
||||||
|
)?
|
||||||
|
)?;
|
||||||
|
|
||||||
|
globals.set("NumberSequence",number_sequence_table)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
impl mlua::UserData for NumberSequence{}
|
||||||
|
type_from_lua_userdata!(NumberSequence);
|
||||||
@@ -34,6 +34,8 @@ fn init(lua:&mlua::Lua)->mlua::Result<()>{
|
|||||||
super::vector3::set_globals(lua,&globals)?;
|
super::vector3::set_globals(lua,&globals)?;
|
||||||
super::cframe::set_globals(lua,&globals)?;
|
super::cframe::set_globals(lua,&globals)?;
|
||||||
super::instance::set_globals(lua,&globals)?;
|
super::instance::set_globals(lua,&globals)?;
|
||||||
|
super::number_sequence::set_globals(lua,&globals)?;
|
||||||
|
super::color_sequence::set_globals(lua,&globals)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ impl Vector3{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 vector3_table=lua.create_table()?;
|
let vector3_table=lua.create_table()?;
|
||||||
|
|
||||||
//Vector3.new
|
//Vector3.new
|
||||||
@@ -35,7 +35,7 @@ impl From<rbx_types::Vector3> for Vector3{
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl mlua::UserData for Vector3{
|
impl mlua::UserData for Vector3{
|
||||||
fn add_fields<'lua,F: mlua::UserDataFields<'lua,Self>>(fields: &mut F){
|
fn add_fields<F:mlua::UserDataFields<Self>>(fields:&mut F){
|
||||||
fields.add_field_method_get("magnitude",|_,this|Ok(this.0.length()));
|
fields.add_field_method_get("magnitude",|_,this|Ok(this.0.length()));
|
||||||
fields.add_field_method_get("x",|_,this|Ok(this.0.x));
|
fields.add_field_method_get("x",|_,this|Ok(this.0.x));
|
||||||
fields.add_field_method_set("x",|_,this,val|{
|
fields.add_field_method_set("x",|_,this,val|{
|
||||||
@@ -54,7 +54,7 @@ impl mlua::UserData for Vector3{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_methods<'lua,M: mlua::UserDataMethods<'lua,Self>>(methods:&mut M){
|
fn add_methods<M:mlua::UserDataMethods<Self>>(methods:&mut M){
|
||||||
//methods.add_method("area",|_,this,()| Ok(this.length * this.width));
|
//methods.add_method("area",|_,this,()| Ok(this.length * this.width));
|
||||||
|
|
||||||
methods.add_meta_function(mlua::MetaMethod::Add,|_,(this,val):(Self,Self)|Ok(Self(this.0+val.0)));
|
methods.add_meta_function(mlua::MetaMethod::Add,|_,(this,val):(Self,Self)|Ok(Self(this.0+val.0)));
|
||||||
|
|||||||
Reference in New Issue
Block a user