diff --git a/assets/tests/callback_to_dynamic_function/can_convert_lua_fn_to_dynamic_function.lua b/assets/tests/callback_to_dynamic_function/can_convert_lua_fn_to_dynamic_function.lua new file mode 100644 index 000000000..0135c9c77 --- /dev/null +++ b/assets/tests/callback_to_dynamic_function/can_convert_lua_fn_to_dynamic_function.lua @@ -0,0 +1,10 @@ +local my_fn = into_script_function( + function(string, list) + print(string, list) + assert(string == "test", "string is not test got: " .. string) + assert(list[1] == "test", "list[1] is not test, got: ".. list[1]) + end +) + +my_fn("test", {"test"}) + diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/script_value.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/script_value.rs index 888f4e821..bd296ef8a 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/script_value.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/script_value.rs @@ -2,10 +2,11 @@ use super::reference::LuaReflectReference; use bevy_mod_scripting_core::{ asset::Language, bindings::{function::script_function::FunctionCallContext, script_value::ScriptValue}, + error::InteropError, }; use mlua::{FromLua, IntoLua, Value, Variadic}; use std::{ - collections::HashMap, + collections::{HashMap, VecDeque}, ops::{Deref, DerefMut}, }; @@ -51,6 +52,20 @@ impl FromLua for LuaScriptValue { Value::Integer(i) => ScriptValue::Integer(i as i64), Value::Number(n) => ScriptValue::Float(n), Value::String(s) => ScriptValue::String(s.to_str()?.to_owned().into()), + Value::Function(f) => ScriptValue::Function( + (move |_context: FunctionCallContext, args: VecDeque| { + println!("Lua function called with args: {:?}", args); + match f.call::( + args.into_iter() + .map(LuaScriptValue) + .collect::>(), + ) { + Ok(v) => v.0, + Err(e) => ScriptValue::Error(InteropError::external_error(Box::new(e))), + } + }) + .into(), + ), Value::Table(table) => { // check the key types, if strings then it's a map let mut iter = table.pairs::(); diff --git a/crates/testing_crates/script_integration_test_harness/src/test_functions.rs b/crates/testing_crates/script_integration_test_harness/src/test_functions.rs index ad658c0a6..138a46373 100644 --- a/crates/testing_crates/script_integration_test_harness/src/test_functions.rs +++ b/crates/testing_crates/script_integration_test_harness/src/test_functions.rs @@ -17,8 +17,8 @@ use bevy_mod_scripting_core::{ script_function::{DynamicScriptFunctionMut, FunctionCallContext}, }, pretty_print::DisplayWithWorld, - ReflectReference, ScriptComponentRegistration, ScriptResourceRegistration, - ScriptTypeRegistration, ScriptValue, + DynamicScriptFunction, ReflectReference, ScriptComponentRegistration, + ScriptResourceRegistration, ScriptTypeRegistration, ScriptValue, }, error::InteropError, }; @@ -144,6 +144,7 @@ pub fn register_test_functions(world: &mut App) { "noop_4_args", |_a: ScriptValue, _b: ScriptValue, _c: ScriptValue, _d: ScriptValue| {}, ) + .register("into_script_function", |f: DynamicScriptFunction| f) .register( "assert_str_eq", |s1: String, s2: String, reason: Option| { diff --git a/other-release-plz.toml b/other-release-plz.toml deleted file mode 100644 index 86f0b8d00..000000000 --- a/other-release-plz.toml +++ /dev/null @@ -1,96 +0,0 @@ -[workspace] -dependencies_update = false -publish_timeout = "30m" -git_release_enable = false -git_tag_enable = false -git_release_body = """ -{{ changelog }} -{% if remote.contributors %} -### Contributors -{% for contributor in remote.contributors | unique(attribute="username") %} -* @{{ contributor.username }} -{% endfor %} -{% endif %} -""" - -[changelog] -commit_parsers = [ - # dont include chore changes in changelog - { message = "^chore.*", skip = true }, - { message = "^test.*", skip = true }, - { message = "^docs.*", skip = true }, - { message = "^feat", group = "added" }, - { message = "^changed", group = "changed" }, - { message = "^deprecated", group = "deprecated" }, - { message = "^fix", group = "fixed" }, - { message = "^security", group = "security" }, - { message = "^.*", group = "other" }, -] - -[[package]] -name = "bevy_mod_scripting" -publish_features = ["lua54"] -version_group = "main" -git_release_latest = true -git_release_enable = true -git_tag_enable = true -git_tag_name = "v{{ version }}" -git_release_name = "v{{ version }}" - -changelog_include = [ - "bevy_mod_scripting_lua", - "bevy_mod_scripting_core", - "bevy_mod_scripting_rhai", - # "bevy_mod_scripting_rune", - "bevy_mod_scripting_functions", -] - -[[package]] -name = "bevy_mod_scripting_lua" -publish_features = ["lua54"] -version_group = "main" - -[[package]] -name = "bevy_mod_scripting_core" -version_group = "main" - -[[package]] -name = "bevy_mod_scripting_derive" -version_group = "main" - -[[package]] -name = "bevy_mod_scripting_rhai" -version_group = "main" - -# [[package]] -# name = "bevy_mod_scripting_rune" -# version_group = "main" - -[[package]] -name = "bevy_mod_scripting_functions" -version_group = "main" - -[[package]] -name = "ladfile" -git_release_enable = true -git_release_latest = false -git_tag_enable = true -git_tag_name = "v{{ version }}-ladfile" -git_release_name = "v{{ version }}-ladfile" - -[[package]] -name = "ladfile_builder" -git_release_enable = true -git_release_latest = false -git_tag_enable = true -git_tag_name = "v{{ version }}-ladfile_builder" -git_release_name = "v{{ version }}-ladfile_builder" - -[[package]] -changelog_update = true -name = "mdbook_lad_preprocessor" -git_release_enable = true -git_release_latest = false -git_tag_enable = true -git_tag_name = "v{{ version }}-mdbook_lad_preprocessor" -git_release_name = "v{{ version }}-mdbook_lad_preprocessor"