From a05dc89132ea2be445be8cd6939576e41602861d Mon Sep 17 00:00:00 2001 From: Piotr Siuszko Date: Fri, 3 May 2024 13:36:56 +0200 Subject: [PATCH] Tests --- Cargo.lock | 24 ++++++++++++------------ Cargo.toml | 19 +++++++++++-------- Makefile | 17 +++++++++++++++++ assets/scripts/game_of_life.lua | 2 ++ src/main.rs | 15 +++++++++++++-- wasm/index.html | 2 +- 6 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 Makefile diff --git a/Cargo.lock b/Cargo.lock index cb50c1b..4807798 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -565,18 +565,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "bevy_github_ci_template" -version = "0.1.0" -dependencies = [ - "bevy", - "bevy_mod_scripting", - "bevy_mod_scripting_core", - "bevy_mod_scripting_lua", - "bevy_script_api", - "rand", -] - [[package]] name = "bevy_gizmos" version = "0.13.2" @@ -986,6 +974,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "bevy_scripting_tests" +version = "0.0.0" +dependencies = [ + "bevy", + "bevy_mod_scripting", + "bevy_mod_scripting_core", + "bevy_mod_scripting_lua", + "bevy_script_api", + "rand", +] + [[package]] name = "bevy_sprite" version = "0.13.2" diff --git a/Cargo.toml b/Cargo.toml index 8a91a9b..f92bc8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,6 @@ [package] -name = "bevy_github_ci_template" -version = "0.1.0" +name = "bevy_scripting_tests" edition = "2021" -license = "MIT OR Apache-2.0 OR CC0-1.0" # Compile with Performance Optimizations: # https://bevyengine.org/learn/book/getting-started/setup/#compile-with-performance-optimizations @@ -17,11 +15,16 @@ opt-level = 3 [dependencies] bevy_mod_scripting = { git = "https://github.com/makspll/bevy_mod_scripting", features = [ - "lua54", "lua", + "lua54", + "lua", "lua_script_api", -], rev ="c497b432b53e7d" } -bevy_mod_scripting_core = { git = "https://github.com/makspll/bevy_mod_scripting", rev ="c497b432b53e7d" } -bevy_mod_scripting_lua = { git = "https://github.com/makspll/bevy_mod_scripting", rev ="c497b432b53e7d" } -bevy_script_api = { git = "https://github.com/makspll/bevy_mod_scripting", rev ="c497b432b53e7d", features= ["lua"] } +], rev = "c497b432b53e7d" } +bevy_mod_scripting_core = { git = "https://github.com/makspll/bevy_mod_scripting", rev = "c497b432b53e7d" } +bevy_mod_scripting_lua = { git = "https://github.com/makspll/bevy_mod_scripting", rev = "c497b432b53e7d", features = [ + "lua54", +] } +bevy_script_api = { git = "https://github.com/makspll/bevy_mod_scripting", rev = "c497b432b53e7d", features = [ + "lua", +] } bevy = { version = "0.13.1", features = ["multi-threaded"] } rand = "0.8.5" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..64fe8c4 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +.DEFAULT_GOAL := web_host + +web_build: + @echo "TEST" + cargo build --target wasm32-unknown-unknown + +web_host: web_build + @echo "TEST2" + wasm-bindgen --out-dir ./out/ --target web ./target/wasm32-unknown-unknown/debug/bevy_scripting_tests.wasm + cp -R assets out/ + cp wasm/* out/ + ls -R out + lwa_simple_server + +prepare: + cargo install lwa_simple_server + cargo install wasm-bindgen-cli \ No newline at end of file diff --git a/assets/scripts/game_of_life.lua b/assets/scripts/game_of_life.lua index 5dd8648..22d56ca 100644 --- a/assets/scripts/game_of_life.lua +++ b/assets/scripts/game_of_life.lua @@ -5,6 +5,8 @@ function init() local life_state = world:get_component(entity, LifeState) local cells = life_state.cells + super_print("Hey, it's me, a Lua!") + -- set some cells alive for _ = 1, 10000 do local index = math.random(#cells) diff --git a/src/main.rs b/src/main.rs index 775889c..2246455 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,8 +29,19 @@ impl APIProvider for LifeAPI { type ScriptContext = Mutex; type DocTarget = LuaDocFragment; - fn attach_api(&mut self, _: &mut Self::APITarget) -> Result<(), ScriptError> { - // we don't actually provide anything global + fn attach_api(&mut self, ctx: &mut Self::APITarget) -> Result<(), ScriptError> { + let ctx = ctx.get_mut().unwrap(); + + ctx.globals() + .set( + "super_print", + ctx.create_function(|_ctx, msg: String| { + info!("[MESSAGE FROM OTHER WORLD]: {}", msg); + Ok(()) + }) + .map_err(ScriptError::new_other)?, + ) + .map_err(ScriptError::new_other)?; Ok(()) } diff --git a/wasm/index.html b/wasm/index.html index ed8eec9..4a75c52 100644 --- a/wasm/index.html +++ b/wasm/index.html @@ -4,7 +4,7 @@