Compare commits
No commits in common. "35b4317040924a139213e61f77b51c6c03c091b1" and "ba799ee1101f14362be8e7b15bc2fa47f3559fb1" have entirely different histories.
35b4317040
...
ba799ee110
21 changed files with 158 additions and 242 deletions
|
|
@ -1,15 +0,0 @@
|
||||||
export CARGO_MANIFEST_DIR := `pwd`
|
|
||||||
|
|
||||||
build-deps:
|
|
||||||
cargo clean && cargo build
|
|
||||||
|
|
||||||
_test:
|
|
||||||
mdbook test -L target/debug/deps/
|
|
||||||
|
|
||||||
test: build-deps _test
|
|
||||||
|
|
||||||
test-watch: build-deps
|
|
||||||
watchexec --exts md -r just _test
|
|
||||||
|
|
||||||
serve:
|
|
||||||
mdbook serve
|
|
||||||
|
|
@ -24,10 +24,7 @@ bevy_scriptum's main advantages include:
|
||||||
Scripts are separate files that can be hot-reloaded at runtime. This allows you to quickly iterate on your game logic without having to recompile it.
|
Scripts are separate files that can be hot-reloaded at runtime. This allows you to quickly iterate on your game logic without having to recompile it.
|
||||||
|
|
||||||
All you need to do is register callbacks on your Bevy app like this:
|
All you need to do is register callbacks on your Bevy app like this:
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -50,11 +47,7 @@ hello_bevy()
|
||||||
|
|
||||||
Every callback function that you expose to the scripting language is also a Bevy system, so you can easily query and mutate ECS components and resources just like you would in a regular Bevy system:
|
Every callback function that you expose to the scripting language is also a Bevy system, so you can easily query and mutate ECS components and resources just like you would in a regular Bevy system:
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_ecs;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -80,10 +73,7 @@ fn main() {
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also pass arguments to your callback functions, just like you would in a regular Bevy system - using `In` structs with tuples:
|
You can also pass arguments to your callback functions, just like you would in a regular Bevy system - using `In` structs with tuples:
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -120,10 +110,7 @@ or execute `cargo add bevy_scriptum --features lua` from your project directory.
|
||||||
|
|
||||||
You can now start exposing functions to the scripting language. For example, you can expose a function that prints a message to the console:
|
You can now start exposing functions to the scripting language. For example, you can expose a function that prints a message to the console:
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -151,10 +138,7 @@ my_print("Hello world!")
|
||||||
|
|
||||||
And spawn an entity with attached `Script` component with a handle to a script source file:
|
And spawn an entity with attached `Script` component with a handle to a script source file:
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -199,10 +183,7 @@ end)
|
||||||
```
|
```
|
||||||
which will print out `John` when used with following exposed function:
|
which will print out `John` when used with following exposed function:
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
|
||||||
|
|
@ -20,17 +20,14 @@ bevy_scriptum provides following types that can be used in Lua:
|
||||||
|
|
||||||
### Example Lua usage
|
### Example Lua usage
|
||||||
|
|
||||||
```lua
|
```
|
||||||
my_vec = Vec3(1, 2, 3)
|
my_vec = Vec3(1, 2, 3)
|
||||||
set_translation(entity, my_vec)
|
set_translation(entity, my_vec)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example Rust usage
|
### Example Rust usage
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -72,10 +69,7 @@ pass_to_rust(entity)
|
||||||
|
|
||||||
### Example Rust usage
|
### Example Rust usage
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,7 @@
|
||||||
To call a rust function from Lua first you need to register a function
|
To call a rust function from Lua first you need to register a function
|
||||||
within Rust using builder pattern.
|
within Rust using builder pattern.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -23,10 +20,7 @@ fn main() {
|
||||||
|
|
||||||
For example to register a function called `my_rust_func` you can do the following:
|
For example to register a function called `my_rust_func` you can do the following:
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -55,10 +49,7 @@ that implements `FromLua`.
|
||||||
Since a registered callback function is a Bevy system, the parameters are passed
|
Since a registered callback function is a Bevy system, the parameters are passed
|
||||||
to it as `In` struct with tuple, which has to be the first parameter of the closure.
|
to it as `In` struct with tuple, which has to be the first parameter of the closure.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -77,10 +68,7 @@ fn main() {
|
||||||
|
|
||||||
To make it look nicer you can destructure the `In` struct.
|
To make it look nicer you can destructure the `In` struct.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -109,10 +97,7 @@ Any registered rust function that returns a value will retrurn a promise when
|
||||||
called within a script. By calling `:and_then` on the promise you can register
|
called within a script. By calling `:and_then` on the promise you can register
|
||||||
a callback that will receive the value returned from Rust function.
|
a callback that will receive the value returned from Rust function.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,7 @@ of the function to call, `LuaScriptData` that has been automatically
|
||||||
attached to entity after an entity with script attached has been spawned
|
attached to entity after an entity with script attached has been spawned
|
||||||
and its script evaluated, the entity and optionally some arguments.
|
and its script evaluated, the entity and optionally some arguments.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -32,15 +29,14 @@ fn call_lua_on_update_from_rust(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
```
|
```
|
||||||
|
|
||||||
We can also pass some arguments by providing a tuple or `Vec` as the last
|
We can also pass some arguments by providing a tuple or `Vec` as the last
|
||||||
`call_fn` argument.
|
`call_fn` argument.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -55,6 +51,8 @@ fn call_lua_on_update_from_rust(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
```
|
```
|
||||||
|
|
||||||
They will be passed to `on_update` Lua function
|
They will be passed to `on_update` Lua function
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,7 @@ a create feature.
|
||||||
|
|
||||||
You can now start exposing functions to the scripting language. For example, you can expose a function that prints a message to the console:
|
You can now start exposing functions to the scripting language. For example, you can expose a function that prints a message to the console:
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -43,10 +40,7 @@ my_print("Hello world!")
|
||||||
|
|
||||||
And spawn an entity with attached `Script` component with a handle to a script source file:
|
And spawn an entity with attached `Script` component with a handle to a script source file:
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,7 @@ That allows you to do anything you would do in a Bevy system.
|
||||||
You could for example create a callback system function that prints names
|
You could for example create a callback system function that prints names
|
||||||
of all entities with `Player` component.
|
of all entities with `Player` component.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_ecs;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -46,11 +42,7 @@ You can use functions that interact with Bevy entities and resources and
|
||||||
take arguments at the same time. It could be used for example to mutate a
|
take arguments at the same time. It could be used for example to mutate a
|
||||||
component.
|
component.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_ecs;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -67,7 +59,7 @@ fn main() {
|
||||||
runtime.add_function(
|
runtime.add_function(
|
||||||
String::from("hurt_player"),
|
String::from("hurt_player"),
|
||||||
|In((hit_value,)): In<(i32,)>, mut players: Query<&mut Player>| {
|
|In((hit_value,)): In<(i32,)>, mut players: Query<&mut Player>| {
|
||||||
let mut player = players.single_mut().unwrap();
|
let mut player = players.single_mut();
|
||||||
player.health -= hit_value;
|
player.health -= hit_value;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,6 @@ To spawn a Lua script you will need to get a handle to a script asset using
|
||||||
bevy's `AssetServer`.
|
bevy's `AssetServer`.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -16,6 +13,8 @@ fn my_spawner(mut commands: Commands, assets_server: Res<AssetServer>) {
|
||||||
assets_server.load("my_script.lua"),
|
assets_server.load("my_script.lua"),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
```
|
```
|
||||||
|
|
||||||
After they scripts have been evaled by bevy_scriptum, the entities that they've
|
After they scripts have been evaled by bevy_scriptum, the entities that they've
|
||||||
|
|
@ -25,9 +24,6 @@ been attached to will get the `Script::<LuaScript>` component stripped and inste
|
||||||
So to query scipted entities you could do something like:
|
So to query scipted entities you could do something like:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
@ -39,4 +35,6 @@ fn my_system(
|
||||||
// do something with scripted entities
|
// do something with scripted entities
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,27 @@
|
||||||
# Builtin types
|
# Builtin types
|
||||||
|
|
||||||
bevy_scriptum provides following types that can be used in Ruby:
|
bevy_scriptum provides following types that can be used in Lua:
|
||||||
|
|
||||||
- ```Bevy::Vec3```
|
- ```Vec3```
|
||||||
- ```Bevy::Entity```
|
- ```BevyEntity```
|
||||||
|
|
||||||
## Vec3
|
## Vec3
|
||||||
|
|
||||||
### Class Methods
|
### Constructor
|
||||||
|
|
||||||
- `new(x, y, z)`
|
`Vec3(x: number, y: number, z: number)`
|
||||||
- `current`
|
|
||||||
|
|
||||||
### Instance Methods
|
### Properties
|
||||||
|
|
||||||
- `x`
|
- `x: number`
|
||||||
- `y`
|
- `y: number`
|
||||||
- `z`
|
- `z: number`
|
||||||
|
|
||||||
### Example Ruby usage
|
|
||||||
|
|
||||||
```ruby
|
### Example Lua usage
|
||||||
my_vec = Bevy::Vec3.new(1, 2, 3)
|
|
||||||
|
```lua
|
||||||
|
my_vec = Vec3(1, 2, 3)
|
||||||
set_translation(entity, my_vec)
|
set_translation(entity, my_vec)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -33,12 +33,12 @@ set_translation(entity, my_vec)
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_scripting::<RubyRuntime>(|runtime| {
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
runtime.add_function(String::from("set_translation"), set_translation);
|
runtime.add_function(String::from("set_translation"), set_translation);
|
||||||
})
|
})
|
||||||
.run();
|
.run();
|
||||||
|
|
@ -63,11 +63,11 @@ None - instances can only be acquired by using built-in `entity` global variable
|
||||||
|
|
||||||
- `index: integer`
|
- `index: integer`
|
||||||
|
|
||||||
### Example Ruby usage
|
### Example Lua usage
|
||||||
|
|
||||||
```ruby
|
```lua
|
||||||
puts(Bevy::Entity.current.index)
|
print(entity.index)
|
||||||
pass_to_rust(Bevy::Entity.current)
|
pass_to_rust(entity)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example Rust usage
|
### Example Rust usage
|
||||||
|
|
@ -78,12 +78,12 @@ pass_to_rust(Bevy::Entity.current)
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_scripting::<RubyRuntime>(|runtime| {
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
runtime.add_function(String::from("pass_to_rust"), |In((entity,)): In<(BevyEntity,)>| {
|
runtime.add_function(String::from("pass_to_rust"), |In((entity,)): In<(BevyEntity,)>| {
|
||||||
println!("pass_to_rust called with entity: {:?}", entity);
|
println!("pass_to_rust called with entity: {:?}", entity);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
## entity
|
## entity
|
||||||
|
|
||||||
Current entity that the script is atteched to can be retrieved by calling `Bevy::Entity.current`.
|
A variable called `entity` is automatically available to all scripts - it represents bevy entity that the `Script` component is attached to.
|
||||||
It exposes `index` method that returns bevy entity index.
|
It exposes `index` property that returns bevy entity index.
|
||||||
It is useful for accessing entity's components from scripts.
|
It is useful for accessing entity's components from scripts.
|
||||||
It can be used in the following way:
|
It can be used in the following way:
|
||||||
```ruby
|
```lua
|
||||||
puts("Current entity index: #{Bevy::Entity.current.index}")
|
print("Current entity index: " .. entity.index)
|
||||||
```
|
```
|
||||||
|
|
||||||
`Bevy::Entity.current` variable is currently not available within promise callbacks.
|
`entity` variable is currently not available within promise callbacks.
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,17 @@
|
||||||
# Calling Rust from Ruby
|
# Calling Rust from Lua
|
||||||
|
|
||||||
To call a rust function from Ruby first you need to register a function
|
To call a rust function from Lua first you need to register a function
|
||||||
within Rust using builder pattern.
|
within Rust using builder pattern.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_scripting::<RubyRuntime>(|runtime| {
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
// `runtime` is a builder that you can use to register functions
|
// `runtime` is a builder that you can use to register functions
|
||||||
})
|
})
|
||||||
.run();
|
.run();
|
||||||
|
|
@ -23,18 +20,15 @@ fn main() {
|
||||||
|
|
||||||
For example to register a function called `my_rust_func` you can do the following:
|
For example to register a function called `my_rust_func` you can do the following:
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_scripting::<RubyRuntime>(|runtime| {
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
runtime.add_function(String::from("my_rust_func"), || {
|
runtime.add_function(String::from("my_rust_func"), || {
|
||||||
println!("my_rust_func has been called");
|
println!("my_rust_func has been called");
|
||||||
});
|
});
|
||||||
|
|
@ -43,27 +37,27 @@ fn main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
After you do that the function will be available to Ruby code in your spawned scripts.
|
After you do that the function will be available to Lua code in your spawned scripts.
|
||||||
|
|
||||||
```ruby
|
```lua
|
||||||
my_rust_func
|
my_rust_func()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Registered functions can also take parameters. A parameter can be any type
|
||||||
|
that implements `FromLua`.
|
||||||
|
|
||||||
Since a registered callback function is a Bevy system, the parameters are passed
|
Since a registered callback function is a Bevy system, the parameters are passed
|
||||||
to it as `In` struct with tuple, which has to be the first parameter of the closure.
|
to it as `In` struct with tuple, which has to be the first parameter of the closure.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_scripting::<RubyRuntime>(|runtime| {
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
runtime.add_function(String::from("func_with_params"), |args: In<(String, i64)>| {
|
runtime.add_function(String::from("func_with_params"), |args: In<(String, i64)>| {
|
||||||
println!("my_rust_func has been called with string {} and i64 {}", args.0.0, args.0.1);
|
println!("my_rust_func has been called with string {} and i64 {}", args.0.0, args.0.1);
|
||||||
});
|
});
|
||||||
|
|
@ -74,18 +68,15 @@ fn main() {
|
||||||
|
|
||||||
To make it look nicer you can destructure the `In` struct.
|
To make it look nicer you can destructure the `In` struct.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_scripting::<RubyRuntime>(|runtime| {
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
runtime.add_function(String::from("func_with_params"), |In((a, b)): In<(String, i64)>| {
|
runtime.add_function(String::from("func_with_params"), |In((a, b)): In<(String, i64)>| {
|
||||||
println!("my_rust_func has been called with string {} and i64 {}", a, b);
|
println!("my_rust_func has been called with string {} and i64 {}", a, b);
|
||||||
});
|
});
|
||||||
|
|
@ -94,9 +85,9 @@ fn main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The above function can be called from Ruby
|
The above function can be called from Lua
|
||||||
|
|
||||||
```ruby
|
```lua
|
||||||
func_with_params("abc", 123)
|
func_with_params("abc", 123)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -106,18 +97,15 @@ Any registered rust function that returns a value will retrurn a promise when
|
||||||
called within a script. By calling `:and_then` on the promise you can register
|
called within a script. By calling `:and_then` on the promise you can register
|
||||||
a callback that will receive the value returned from Rust function.
|
a callback that will receive the value returned from Rust function.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_scripting::<RubyRuntime>(|runtime| {
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
runtime.add_function(String::from("returns_value"), || {
|
runtime.add_function(String::from("returns_value"), || {
|
||||||
123
|
123
|
||||||
});
|
});
|
||||||
|
|
@ -126,8 +114,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```ruby
|
```lua
|
||||||
returns_value.and_then do |value|
|
returns_value():and_then(function (value)
|
||||||
puts(value) # 123
|
print(value) -- 123
|
||||||
end
|
end)
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,53 +1,49 @@
|
||||||
# Calling Ruby from Rust
|
# Calling Lua from Rust
|
||||||
|
|
||||||
To call a function defined in Ruby
|
To call a function defined in Lua
|
||||||
|
|
||||||
```ruby
|
```lua
|
||||||
def on_update
|
function on_update()
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
We need to acquire `RubyRuntime` resource within a bevy system.
|
We need to acquire `LuaRuntime` resource within a bevy system.
|
||||||
Then we will be able to call `call_fn` on it, providing the name
|
Then we will be able to call `call_fn` on it, providing the name
|
||||||
of the function to call, `RubyScriptData` that has been automatically
|
of the function to call, `LuaScriptData` that has been automatically
|
||||||
attached to entity after an entity with script attached has been spawned
|
attached to entity after an entity with script attached has been spawned
|
||||||
and its script evaluated, the entity and optionally some arguments.
|
and its script evaluated, the entity and optionally some arguments.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn call_ruby_on_update_from_rust(
|
fn call_lua_on_update_from_rust(
|
||||||
mut scripted_entities: Query<(Entity, &mut RubyScriptData)>,
|
mut scripted_entities: Query<(Entity, &mut LuaScriptData)>,
|
||||||
scripting_runtime: ResMut<RubyRuntime>,
|
scripting_runtime: ResMut<LuaRuntime>,
|
||||||
) {
|
) {
|
||||||
for (entity, mut script_data) in &mut scripted_entities {
|
for (entity, mut script_data) in &mut scripted_entities {
|
||||||
// calling function named `on_update` defined in Ruby script
|
// calling function named `on_update` defined in lua script
|
||||||
scripting_runtime
|
scripting_runtime
|
||||||
.call_fn("on_update", &mut script_data, entity, ())
|
.call_fn("on_update", &mut script_data, entity, ())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
```
|
```
|
||||||
|
|
||||||
We can also pass some arguments by providing a tuple or `Vec` as the last
|
We can also pass some arguments by providing a tuple or `Vec` as the last
|
||||||
`call_fn` argument.
|
`call_fn` argument.
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn call_ruby_on_update_from_rust(
|
fn call_lua_on_update_from_rust(
|
||||||
mut scripted_entities: Query<(Entity, &mut RubyScriptData)>,
|
mut scripted_entities: Query<(Entity, &mut LuaScriptData)>,
|
||||||
scripting_runtime: ResMut<RubyRuntime>,
|
scripting_runtime: ResMut<LuaRuntime>,
|
||||||
) {
|
) {
|
||||||
for (entity, mut script_data) in &mut scripted_entities {
|
for (entity, mut script_data) in &mut scripted_entities {
|
||||||
scripting_runtime
|
scripting_runtime
|
||||||
|
|
@ -55,12 +51,17 @@ fn call_ruby_on_update_from_rust(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
```
|
```
|
||||||
|
|
||||||
They will be passed to `on_update` Ruby function
|
They will be passed to `on_update` Lua function
|
||||||
```ruby
|
```lua
|
||||||
def on_update(a, b)
|
function on_update(a, b)
|
||||||
puts(a) # 123
|
print(a) -- 123
|
||||||
puts(b) # hello
|
print(b) -- hello
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Any type that implements `IntoLua` can be passed as an argument withing the
|
||||||
|
tuple in `call_fn`.
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,15 @@ a create feature.
|
||||||
|
|
||||||
You can now start exposing functions to the scripting language. For example, you can expose a function that prints a message to the console:
|
You can now start exposing functions to the scripting language. For example, you can expose a function that prints a message to the console:
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_scripting::<RubyRuntime>(|runtime| {
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
runtime.add_function(
|
runtime.add_function(
|
||||||
String::from("my_print"),
|
String::from("my_print"),
|
||||||
|In((x,)): In<(String,)>| {
|
|In((x,)): In<(String,)>| {
|
||||||
|
|
@ -35,26 +32,23 @@ fn main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you can create a script file in `assets` directory called `script.rb` that calls this function:
|
Then you can create a script file in `assets` directory called `script.lua` that calls this function:
|
||||||
|
|
||||||
```ruby
|
```lua
|
||||||
my_print("Hello world!")
|
my_print("Hello world!")
|
||||||
```
|
```
|
||||||
|
|
||||||
And spawn an entity with attached `Script` component with a handle to a script source file:
|
And spawn an entity with attached `Script` component with a handle to a script source file:
|
||||||
|
|
||||||
```rust,no_run
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_scripting::<RubyRuntime>(|runtime| {
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
runtime.add_function(
|
runtime.add_function(
|
||||||
String::from("my_print"),
|
String::from("my_print"),
|
||||||
|In((x,)): In<(String,)>| {
|
|In((x,)): In<(String,)>| {
|
||||||
|
|
@ -63,7 +57,7 @@ fn main() {
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.add_systems(Startup,|mut commands: Commands, asset_server: Res<AssetServer>| {
|
.add_systems(Startup,|mut commands: Commands, asset_server: Res<AssetServer>| {
|
||||||
commands.spawn(Script::<RubyScript>::new(asset_server.load("script.rb")));
|
commands.spawn(Script::<LuaScript>::new(asset_server.load("script.lua")));
|
||||||
})
|
})
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ Add the following to your `Cargo.toml`:
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.16"
|
bevy = "0.16"
|
||||||
bevy_scriptum = { version = "0.8", features = ["ruby"] }
|
bevy_scriptum = { version = "0.8", features = ["lua"] }
|
||||||
```
|
```
|
||||||
|
|
||||||
If you need a different version of bevy you need to use a matching bevy_scriptum
|
If you need a different version of bevy you need to use a matching bevy_scriptum
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ of all entities with `Player` component.
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Player;
|
struct Player;
|
||||||
|
|
@ -22,7 +22,7 @@ struct Player;
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_scripting::<RubyRuntime>(|runtime| {
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
runtime.add_function(
|
runtime.add_function(
|
||||||
String::from("print_player_names"),
|
String::from("print_player_names"),
|
||||||
|players: Query<&Name, With<Player>>| {
|
|players: Query<&Name, With<Player>>| {
|
||||||
|
|
@ -38,8 +38,8 @@ fn main() {
|
||||||
|
|
||||||
In script:
|
In script:
|
||||||
|
|
||||||
```ruby
|
```lua
|
||||||
print_player_names
|
print_player_names()
|
||||||
```
|
```
|
||||||
|
|
||||||
You can use functions that interact with Bevy entities and resources and
|
You can use functions that interact with Bevy entities and resources and
|
||||||
|
|
@ -53,7 +53,7 @@ component.
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Player {
|
struct Player {
|
||||||
|
|
@ -63,7 +63,7 @@ struct Player {
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_scripting::<RubyRuntime>(|runtime| {
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
runtime.add_function(
|
runtime.add_function(
|
||||||
String::from("hurt_player"),
|
String::from("hurt_player"),
|
||||||
|In((hit_value,)): In<(i32,)>, mut players: Query<&mut Player>| {
|
|In((hit_value,)): In<(i32,)>, mut players: Query<&mut Player>| {
|
||||||
|
|
@ -78,6 +78,6 @@ fn main() {
|
||||||
|
|
||||||
And it could be called in script like:
|
And it could be called in script like:
|
||||||
|
|
||||||
```ruby
|
```lua
|
||||||
hurt_player(5)
|
hurt_player(5)
|
||||||
```
|
```
|
||||||
|
|
|
||||||
3
book/src/ruby/lua.md
Normal file
3
book/src/ruby/lua.md
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Lua
|
||||||
|
|
||||||
|
This chapter demonstrates how to work with bevy_scriptum when using Lua language runtime.
|
||||||
|
|
@ -1,3 +1 @@
|
||||||
# Ruby
|
# Ruby
|
||||||
|
|
||||||
This chapter demonstrates how to work with bevy_scriptum when using Ruby language runtime.
|
|
||||||
|
|
|
||||||
|
|
@ -4,39 +4,37 @@ To spawn a Lua script you will need to get a handle to a script asset using
|
||||||
bevy's `AssetServer`.
|
bevy's `AssetServer`.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn my_spawner(mut commands: Commands, assets_server: Res<AssetServer>) {
|
fn my_spawner(mut commands: Commands, assets_server: Res<AssetServer>) {
|
||||||
commands.spawn(Script::<RubyScript>::new(
|
commands.spawn(Script::<LuaScript>::new(
|
||||||
assets_server.load("my_script.rb"),
|
assets_server.load("my_script.lua"),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
```
|
```
|
||||||
|
|
||||||
After they scripts have been evaled by bevy_scriptum, the entities that they've
|
After they scripts have been evaled by bevy_scriptum, the entities that they've
|
||||||
been attached to will get the `Script::<RubyScript>` component stripped and instead
|
been attached to will get the `Script::<LuaScript>` component stripped and instead
|
||||||
```RubyScriptData``` component will be attached.
|
```LuaScriptData``` component will be attached.
|
||||||
|
|
||||||
So to query scipted entities you could do something like:
|
So to query scipted entities you could do something like:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
# extern crate bevy;
|
|
||||||
# extern crate bevy_scriptum;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
fn my_system(
|
fn my_system(
|
||||||
mut scripted_entities: Query<(Entity, &mut RubyScriptData)>,
|
mut scripted_entities: Query<(Entity, &mut LuaScriptData)>,
|
||||||
) {
|
) {
|
||||||
for (entity, mut script_data) in &mut scripted_entities {
|
for (entity, mut script_data) in &mut scripted_entities {
|
||||||
// do something with scripted entities
|
// do something with scripted entities
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,8 @@ fn teardown(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
```
|
```
|
||||||
|
|
||||||
And to tie this all together we do the following:
|
And to tie this all together we do the following:
|
||||||
|
|
@ -120,11 +122,11 @@ fn main() {
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
# fn init() {}
|
fn init() {} // Implemented elsewhere
|
||||||
# fn update() {}
|
fn update() {} // Implemented elsewhere
|
||||||
# fn despawn() {}
|
fn despawn() {} // Implemented elsewhere
|
||||||
# fn teardown() {}
|
fn teardown() {} // Implemented elsewhere
|
||||||
# fn spawn_player() {}
|
fn spawn_player() {} // Implemented elsewhere
|
||||||
```
|
```
|
||||||
|
|
||||||
`despawn` can be implemented as:
|
`despawn` can be implemented as:
|
||||||
|
|
@ -139,6 +141,8 @@ use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
fn despawn(In((entity,)): In<(BevyEntity,)>, mut commands: Commands) {
|
fn despawn(In((entity,)): In<(BevyEntity,)>, mut commands: Commands) {
|
||||||
commands.entity(entity.0).despawn();
|
commands.entity(entity.0).despawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {} // Implemented elsewhere
|
||||||
```
|
```
|
||||||
|
|
||||||
Implementation of `spawn_player` has been left out as an exercise for the reader.
|
Implementation of `spawn_player` has been left out as an exercise for the reader.
|
||||||
|
|
|
||||||
3
book/test.sh
Executable file
3
book/test.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
CARGO_MANIFEST_DIR=$(pwd) cargo clean && cargo build && mdbook test -L target/debug/deps/
|
||||||
|
|
@ -174,7 +174,7 @@ fn then(r_self: magnus::Value) -> magnus::Value {
|
||||||
.into_value()
|
.into_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
#[magnus::wrap(class = "Bevy::Entity")]
|
#[magnus::wrap(class = "Bevy::Entity")]
|
||||||
pub struct BevyEntity(pub Entity);
|
pub struct BevyEntity(pub Entity);
|
||||||
|
|
||||||
|
|
@ -191,7 +191,7 @@ impl TryConvert for BevyEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
#[magnus::wrap(class = "Bevy::Vec3")]
|
#[magnus::wrap(class = "Bevy::Vec3")]
|
||||||
pub struct BevyVec3(pub Vec3);
|
pub struct BevyVec3(pub Vec3);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue