Create an early scripting engine #2

Merged
SeanOMik merged 42 commits from feature/early-scripting into main 2024-03-03 03:28:57 +00:00
11 changed files with 834 additions and 53 deletions
Showing only changes of commit de4fb76f31 - Show all commits

846
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@ edition = "2021"
[dependencies] [dependencies]
lyra-engine = { path = "../../", version = "0.0.1", features = ["lua_scripting"] } lyra-engine = { path = "../../", version = "0.0.1", features = ["lua_scripting"] }
lyra-scripting = { path = "../../lyra-scripting", features = ["lua", "teal"] }
#lyra-ecs = { path = "../../lyra-ecs"} #lyra-ecs = { path = "../../lyra-ecs"}
anyhow = "1.0.75" anyhow = "1.0.75"
async-std = "1.12.0" async-std = "1.12.0"

View File

@ -8,6 +8,7 @@ edition = "2021"
[features] [features]
default = ["lua"] default = ["lua"]
lua = ["dep:elua"] lua = ["dep:elua"]
teal = ["lua", "elua/teal"]
[dependencies] [dependencies]
lyra-scripting-derive = { path = "lyra-scripting-derive" } lyra-scripting-derive = { path = "lyra-scripting-derive" }

@ -1 +1 @@
Subproject commit 936ea606343dbcf5321b4b988de65daf8769ff3f Subproject commit feb93f2b4ed7063e4fba366377b039ba4f9026ef

View File

@ -670,7 +670,7 @@ pub fn wrap_math_vec_copy(input: proc_macro::TokenStream) -> proc_macro::TokenSt
stringify!(#type_name).to_string() stringify!(#type_name).to_string()
} }
fn build<'a>(_: &elua::State, builder: &mut elua::UserdataBuilder<'a, Self>) -> elua::Result<()> { fn build<'a>(builder: &mut elua::UserdataBuilder<'a, Self>) {
#(#field_get_set_pairs)* #(#field_get_set_pairs)*
#matrix_wrapper_fields #matrix_wrapper_fields
@ -694,8 +694,6 @@ pub fn wrap_math_vec_copy(input: proc_macro::TokenStream) -> proc_macro::TokenSt
#vec_wrapper_methods #vec_wrapper_methods
#custom_methods #custom_methods
Ok(())
} }
} }

View File

@ -174,9 +174,7 @@ impl elua::Userdata for ScriptBorrow {
"ScriptBorrow".to_string() "ScriptBorrow".to_string()
} }
fn build<'a>(_: &elua::State, _: &mut elua::UserdataBuilder<'a, Self>) -> elua::Result<()> { fn build<'a>(_: &mut elua::UserdataBuilder<'a, Self>) { }
Ok(())
}
} }
/// Helper function used for reflecting userdata as a ScriptBorrow /// Helper function used for reflecting userdata as a ScriptBorrow

View File

@ -163,7 +163,7 @@ impl elua::Userdata for ScriptDynamicBundle {
"Bundle".to_string() "Bundle".to_string()
} }
fn build<'a>(_: &elua::State, builder: &mut elua::UserdataBuilder<'a, Self>) -> elua::Result<()> { fn build<'a>(builder: &mut elua::UserdataBuilder<'a, Self>) {
builder builder
.function("new", |_, ()| Ok(ScriptDynamicBundle(DynamicBundle::new()))) .function("new", |_, ()| Ok(ScriptDynamicBundle(DynamicBundle::new())))
.method_mut("push", |_, this, comp: elua::AnyUserdata| { .method_mut("push", |_, this, comp: elua::AnyUserdata| {
@ -175,7 +175,5 @@ impl elua::Userdata for ScriptDynamicBundle {
Ok(()) Ok(())
}); });
Ok(())
} }
} }

View File

@ -25,15 +25,10 @@ impl elua::Userdata for ScriptEntity {
"Entity".to_string() "Entity".to_string()
} }
fn build<'a>( fn build<'a>(builder: &mut elua::userdata::UserdataBuilder<'a, Self>) {
_: &elua::State,
builder: &mut elua::userdata::UserdataBuilder<'a, Self>,
) -> elua::Result<()> {
builder.meta_method(elua::MetaMethod::ToString, |_, this, ()| { builder.meta_method(elua::MetaMethod::ToString, |_, this, ()| {
Ok(format!("{:?}", this.0)) Ok(format!("{:?}", this.0))
}); });
Ok(())
} }
} }
@ -58,10 +53,7 @@ impl elua::Userdata for ScriptWorldPtr {
"World".to_string() "World".to_string()
} }
fn build<'a>( fn build<'a>(builder: &mut elua::UserdataBuilder<'a, Self>) {
_: &elua::State,
builder: &mut elua::UserdataBuilder<'a, Self>,
) -> elua::Result<()> {
builder builder
.method_mut("spawn", |_, this, vals: elua::ValueVec| { .method_mut("spawn", |_, this, vals: elua::ValueVec| {
let world = this.as_mut(); let world = this.as_mut();
@ -312,7 +304,5 @@ impl elua::Userdata for ScriptWorldPtr {
Ok(LuaResHandle::from(handle)) Ok(LuaResHandle::from(handle))
}); });
Ok(())
} }
} }

View File

@ -15,7 +15,7 @@ impl elua::Userdata for LuaActionHandler {
"ActionHandler".to_string() "ActionHandler".to_string()
} }
fn build<'a>(_: &elua::State, builder: &mut elua::UserdataBuilder<'a, Self>) -> elua::Result<()> { fn build<'a>(builder: &mut elua::UserdataBuilder<'a, Self>) {
builder.function("new", |_, table: elua::Table| { builder.function("new", |_, table: elua::Table| {
let mut handler = ActionHandler::new(); let mut handler = ActionHandler::new();
@ -146,7 +146,6 @@ impl elua::Userdata for LuaActionHandler {
Ok(ScriptBorrow::from_resource::<ActionHandler>(None)) Ok(ScriptBorrow::from_resource::<ActionHandler>(None))
}); });
Ok(())
} }
} }

View File

@ -20,7 +20,7 @@ impl elua::Userdata for LuaModelComponent {
"ModelComponent".to_string() "ModelComponent".to_string()
} }
fn build<'a>(_: &elua::State, builder: &mut elua::UserdataBuilder<'a, Self>) -> elua::Result<()> { fn build<'a>(builder: &mut elua::UserdataBuilder<'a, Self>) {
builder builder
.function("new", |_, model: Ref<LuaResHandle>| { .function("new", |_, model: Ref<LuaResHandle>| {
let res = model.0.clone(); let res = model.0.clone();
@ -48,8 +48,6 @@ impl elua::Userdata for LuaModelComponent {
.method(FN_NAME_INTERNAL_REFLECT, |_, this, ()| { .method(FN_NAME_INTERNAL_REFLECT, |_, this, ()| {
Ok(ScriptBorrow::from_component(Some(this.0.clone()))) Ok(ScriptBorrow::from_component(Some(this.0.clone())))
}); });
Ok(())
} }
} }

View File

@ -30,7 +30,7 @@ impl elua::Userdata for LuaResHandle {
"Handle".to_string() "Handle".to_string()
} }
fn build<'a>(_: &elua::State, builder: &mut elua::UserdataBuilder<'a, Self>) -> elua::Result<()> { fn build<'a>(builder: &mut elua::UserdataBuilder<'a, Self>) {
builder.field_getter("path", |_, this| Ok(this.path())); builder.field_getter("path", |_, this| Ok(this.path()));
builder.field_getter("version", |_, this| Ok(this.version())); builder.field_getter("version", |_, this| Ok(this.version()));
builder.field_getter("uuid", |_, this| Ok(this.uuid().to_string())); builder.field_getter("uuid", |_, this| Ok(this.uuid().to_string()));
@ -62,8 +62,6 @@ impl elua::Userdata for LuaResHandle {
} }
} }
}); });
Ok(())
} }
} }