Compare commits

..

No commits in common. "main" and "v0.2.2" have entirely different histories.
main ... v0.2.2

185 changed files with 786 additions and 8759 deletions

View file

@ -1,54 +0,0 @@
name: Book
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache Ruby
id: cache-ruby
uses: actions/cache@v4
with:
path: rubies
key: ${{ runner.os }}-ruby
- name: Install Ruby
if: steps.cache-ruby.outputs.cache-hit != 'true'
env:
CC: clang
run: |
url="https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.4.tar.gz"
prefix=`pwd`/rubies/ruby-3.4
mkdir rubies
mkdir ruby_src
curl -sSL $url | tar -xz
cd ruby-3.4.4
mkdir build
cd build
../configure --without-shared --prefix=$prefix
make install
echo $prefix/bin >> $GITHUB_PATH
- name: Add Ruby to PATH
run: |
prefix=`pwd`/rubies/ruby-3.4
echo $prefix/bin >> $GITHUB_PATH
- name: Install latest mdbook
run: |
tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name')
url="https://github.com/rust-lang/mdbook/releases/download/${tag}/mdbook-${tag}-x86_64-unknown-linux-gnu.tar.gz"
mkdir mdbook
curl -sSL $url | tar -xz --directory=./mdbook
echo `pwd`/mdbook >> $GITHUB_PATH
- name: Test Book
run: |
cd book
export CARGO_MANIFEST_DIR=$(pwd)
cargo build
mdbook test -L target/debug/deps/

View file

@ -1,38 +0,0 @@
name: Deploy book
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: write # To push a branch
pages: write # To push to a GitHub Pages site
id-token: write # To update the deployment status
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install latest mdbook
run: |
tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name')
url="https://github.com/rust-lang/mdbook/releases/download/${tag}/mdbook-${tag}-x86_64-unknown-linux-gnu.tar.gz"
mkdir mdbook
curl -sSL $url | tar -xz --directory=./mdbook
echo `pwd`/mdbook >> $GITHUB_PATH
- name: Build Book
run: |
cd book
mdbook build
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: 'book/book'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

View file

@ -2,48 +2,27 @@ name: Rust
on:
push:
branches: ["main"]
branches: [ "main" ]
pull_request:
branches: ["main"]
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v3
- name: Cache Ruby
id: cache-ruby
uses: actions/cache@v4
with:
path: rubies
key: ${{ runner.os }}-ruby
- name: Install Ruby
if: steps.cache-ruby.outputs.cache-hit != 'true'
env:
CC: clang
run: |
url="https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.4.tar.gz"
prefix=`pwd`/rubies/ruby-3.4
mkdir rubies
mkdir ruby_src
curl -sSL $url | tar -xz
cd ruby-3.4.4
mkdir build
cd build
../configure --without-shared --prefix=$prefix
make install
- name: Add Ruby to PATH
run: |
prefix=`pwd`/rubies/ruby-3.4
echo $prefix/bin >> $GITHUB_PATH
- name: Clippy
run: cargo clippy --all-features --verbose -- -D warnings
- name: Build
run: cargo build --all-features --verbose
- name: Run tests
run: cargo test --all-features --verbose
- uses: actions/checkout@v3
- name: Clippy
run: cargo clippy --verbose -- -D warnings
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Install cargo-examples
run: cargo install cargo-examples
- name: Run all examples
run: cargo examples

1
.gitignore vendored
View file

@ -1,4 +1,3 @@
/target
/Cargo.lock
.vscode
.nvim.lua

View file

@ -1,217 +1,21 @@
[package]
name = "bevy_scriptum"
authors = ["Jaroslaw Konik <konikjar@gmail.com>"]
version = "0.9.1"
edition = "2024"
version = "0.2.2"
edition = "2021"
license = "MIT OR Apache-2.0"
readme = "README.md"
categories = ["game-development"]
description = "Plugin for Bevy engine that allows you to write some of your game or application logic in a scripting language"
description = "Plugin for Bevy engine that allows you to write some of your game logic in a scripting language"
repository = "https://github.com/jarkonik/bevy_scriptum"
keywords = ["bevy", "lua", "scripting", "game", "script"]
keywords = ["bevy", "rhai", "scripting", "game", "gamedev"]
[features]
lua = ["dep:mlua", "mlua/luajit"]
rhai = ["dep:rhai"]
ruby = ["dep:magnus", "dep:rb-sys"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = { default-features = false, version = "0.16", features = ["bevy_asset", "bevy_log"] }
bevy = { default-features = false, version = "0.11.0", features = [
"bevy_asset",
] }
serde = "1.0.162"
rhai = { version = "1.14.0", features = [
"sync",
"internals",
"unchecked",
], optional = true }
thiserror = "1.0.40"
anyhow = "1.0.82"
tracing = "0.1.40"
mlua = { version = "0.9.8", features = [
"luajit",
"vendored",
"send",
], optional = true }
magnus = { version = "0.7.1", optional = true }
rb-sys = { version = "0.9", default-features = false, features = ["link-ruby", "ruby-static"], optional = true }
crossbeam-channel = "0.5.15"
libc = "0.2.172"
[[example]]
name = "call_function_from_rust_rhai"
path = "examples/rhai/call_function_from_rust.rs"
required-features = ["rhai"]
[[example]]
name = "current_entity_rhai"
path = "examples/rhai/current_entity.rs"
required-features = ["rhai"]
[[example]]
name = "custom_type_rhai"
path = "examples/rhai/custom_type.rs"
required-features = ["rhai"]
[[example]]
name = "ecs_rhai"
path = "examples/rhai/ecs.rs"
required-features = ["rhai"]
[[example]]
name = "entity_variable_rhai"
path = "examples/rhai/entity_variable.rs"
required-features = ["rhai"]
[[example]]
name = "function_params_rhai"
path = "examples/rhai/function_params.rs"
required-features = ["rhai"]
[[example]]
name = "hello_world_rhai"
path = "examples/rhai/hello_world.rs"
required-features = ["rhai"]
[[example]]
name = "multiple_plugins_rhai"
path = "examples/rhai/multiple_plugins.rs"
required-features = ["rhai"]
[[example]]
name = "non_closure_system_rhai"
path = "examples/rhai/non_closure_system.rs"
required-features = ["rhai"]
[[example]]
name = "promises_rhai"
path = "examples/rhai/promises.rs"
required-features = ["rhai"]
[[example]]
name = "side_effects_rhai"
path = "examples/rhai/side_effects.rs"
required-features = ["rhai"]
[[example]]
name = "function_return_value_rhai"
path = "examples/rhai/function_return_value.rs"
required-features = ["rhai"]
[[example]]
name = "call_function_from_rust_lua"
path = "examples/lua/call_function_from_rust.rs"
required-features = ["lua"]
[[example]]
name = "current_entity_lua"
path = "examples/lua/current_entity.rs"
required-features = ["lua"]
[[example]]
name = "custom_type_lua"
path = "examples/lua/custom_type.rs"
required-features = ["lua"]
[[example]]
name = "ecs_lua"
path = "examples/lua/ecs.rs"
required-features = ["lua"]
[[example]]
name = "entity_variable_lua"
path = "examples/lua/entity_variable.rs"
required-features = ["lua"]
[[example]]
name = "function_params_lua"
path = "examples/lua/function_params.rs"
required-features = ["lua"]
[[example]]
name = "hello_world_lua"
path = "examples/lua/hello_world.rs"
required-features = ["lua"]
[[example]]
name = "multiple_plugins_lua"
path = "examples/lua/multiple_plugins.rs"
required-features = ["lua"]
[[example]]
name = "non_closure_system_lua"
path = "examples/lua/non_closure_system.rs"
required-features = ["lua"]
[[example]]
name = "promises_lua"
path = "examples/lua/promises.rs"
required-features = ["lua"]
[[example]]
name = "side_effects_lua"
path = "examples/lua/side_effects.rs"
required-features = ["lua"]
[[example]]
name = "function_return_value_lua"
path = "examples/lua/function_return_value.rs"
required-features = ["lua"]
[[example]]
name = "call_function_from_rust_ruby"
path = "examples/ruby/call_function_from_rust.rs"
required-features = ["ruby"]
[[example]]
name = "current_entity_ruby"
path = "examples/ruby/current_entity.rs"
required-features = ["ruby"]
[[example]]
name = "custom_type_ruby"
path = "examples/ruby/custom_type.rs"
required-features = ["ruby"]
[[example]]
name = "ecs_ruby"
path = "examples/ruby/ecs.rs"
required-features = ["ruby"]
[[example]]
name = "entity_variable_ruby"
path = "examples/ruby/entity_variable.rs"
required-features = ["ruby"]
[[example]]
name = "function_params_ruby"
path = "examples/ruby/function_params.rs"
required-features = ["ruby"]
[[example]]
name = "function_return_value_ruby"
path = "examples/ruby/function_return_value.rs"
required-features = ["ruby"]
[[example]]
name = "hello_world_ruby"
path = "examples/ruby/hello_world.rs"
required-features = ["ruby"]
[[example]]
name = "multiple_plugins_ruby"
path = "examples/ruby/multiple_plugins.rs"
required-features = ["ruby"]
[[example]]
name = "promises_ruby"
path = "examples/ruby/promises.rs"
required-features = ["ruby"]
[[example]]
name = "side_effects_ruby"
path = "examples/ruby/side_effects.rs"
required-features = ["ruby"]
[dev-dependencies]
tracing-subscriber = "0.3.18"
mlua = { version = "0.9.8", features = ["luajit", "vendored", "send"] }
rhai = { version = "1.14.0", features = ["sync", "internals", "unchecked"] }
thiserror = "1.0.40"

187
README.md
View file

@ -1,47 +1,32 @@
# bevy_scriptum 📜
![demo](demo.gif)
bevy_scriptum is a a plugin for [Bevy](https://bevyengine.org/) that allows you to write some of your game logic in a scripting language.
Currently, only [Rhai](https://rhai.rs/) is supported, but more languages may be added in the future.
bevy_scriptum is a a plugin for [Bevy](https://bevyengine.org/) that allows you to write some of your game or application logic in a scripting language.
### Supported scripting languages/runtimes
| language/runtime | cargo feature | documentation chapter |
| ------------------------------------------ | ------------- | --------------------------------------------------------------- |
| 🌙 LuaJIT | `lua` | [link](https://jarkonik.github.io/bevy_scriptum/lua/lua.html) |
| 🌾 Rhai | `rhai` | [link](https://jarkonik.github.io/bevy_scriptum/rhai/rhai.html) |
| 💎 Ruby(currently only supported on Linux) | `ruby` | [link](https://jarkonik.github.io/bevy_scriptum/ruby/ruby.html) |
Documentation book is available [here](https://jarkonik.github.io/bevy_scriptum/) 📖
Full API docs are available at [docs.rs](https://docs.rs/bevy_scriptum/latest/bevy_scriptum/) 🧑‍💻
bevy_scriptum's main advantages include:
It's main advantages include:
- low-boilerplate
- easy to use
- asynchronicity with a promise-based API
- flexibility
- hot-reloading
Scripts are separate files that can be hot-reloaded at runtime. This allows you to quickly iterate on your game or application 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 your game.
All you need to do is register callbacks on your Bevy app like this:
```rust
use bevy::prelude::*;
use bevy_scriptum::prelude::*;
use bevy_scriptum::runtimes::lua::prelude::*;
App::new()
.add_plugins(DefaultPlugins)
.add_scripting::<LuaRuntime>(|runtime| {
runtime.add_function(String::from("hello_bevy"), || {
println!("hello bevy, called from script");
});
})
.run();
.add_plugins(ScriptingPlugin::default())
.add_script_function(String::from("hello_bevy"), || {
println!("hello bevy, called from script");
});
```
And you can call them in your scripts like this:
```lua
hello_bevy()
```rhai
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:
@ -49,47 +34,42 @@ Every callback function that you expose to the scripting language is also a Bevy
```rust
use bevy::prelude::*;
use bevy_scriptum::prelude::*;
use bevy_scriptum::runtimes::lua::prelude::*;
#[derive(Component)]
struct Player;
App::new()
.add_plugins(DefaultPlugins)
.add_scripting::<LuaRuntime>(|runtime| {
runtime.add_function(
String::from("print_player_names"),
|players: Query<&Name, With<Player>>| {
for player in &players {
println!("player name: {}", player);
}
},
);
})
.run();
.add_plugins(ScriptingPlugin::default())
.add_script_function(
String::from("print_player_names"),
|players: Query<&Name, With<Player>>| {
for player in &players {
println!("player name: {}", player);
}
},
);
```
You can also pass arguments to your callback functions, just like you would in a regular Bevy system - using `In` structs with tuples:
```rust
use bevy::prelude::*;
use bevy_scriptum::prelude::*;
use bevy_scriptum::runtimes::lua::prelude::*;
use rhai::ImmutableString;
App::new()
.add_plugins(DefaultPlugins)
.add_scripting::<LuaRuntime>(|runtime| {
runtime.add_function(
String::from("fun_with_string_param"),
|In((x,)): In<(String,)>| {
println!("called with string: '{}'", x);
},
);
})
.run();
.add_plugins(ScriptingPlugin::default())
.add_script_function(
String::from("fun_with_string_param"),
|In((x,)): In<(ImmutableString,)>| {
println!("called with string: '{}'", x);
},
);
```
which you can then call in your script like this:
```lua
fun_with_string_param("Hello world!")
```rhai
fun_with_string_param("Hello world!");
```
### Usage
@ -98,118 +78,95 @@ Add the following to your `Cargo.toml`:
```toml
[dependencies]
bevy_scriptum = { version = "0.9", features = ["lua"] }
bevy_scriptum = "0.2"
```
or execute `cargo add bevy_scriptum --features lua` from your project directory.
or execute `cargo add bevy_scriptum` from your project directory.
Add the following to your `main.rs`:
```rust
use bevy::prelude::*;
use bevy_scriptum::prelude::*;
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(ScriptingPlugin::default())
.run();
```
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
use rhai::ImmutableString;
use bevy::prelude::*;
use bevy_scriptum::prelude::*;
use bevy_scriptum::runtimes::lua::prelude::*;
App::new()
.add_plugins(DefaultPlugins)
.add_scripting::<LuaRuntime>(|runtime| {
runtime.add_function(
String::from("my_print"),
|In((x,)): In<(String,)>| {
println!("my_print: '{}'", x);
},
);
})
.run();
.add_plugins(ScriptingPlugin::default())
.add_script_function(
String::from("my_print"),
|In((x,)): In<(ImmutableString,)>| {
println!("my_print: '{}'", x);
},
);
```
Then you can create a script file in `assets` directory called `script.lua` that calls this function:
Then you can create a script file in `assets` directory called `script.rhai` that calls this function:
```lua
my_print("Hello world!")
```rhai
my_print("Hello world!");
```
And spawn an entity with attached `Script` component with a handle to a script source file:
And spawn a `Script` component with a handle to a script source file`:
```rust
use bevy::prelude::*;
use bevy_scriptum::prelude::*;
use bevy_scriptum::runtimes::lua::prelude::*;
use bevy_scriptum::Script;
App::new()
.add_plugins(DefaultPlugins)
.add_scripting::<LuaRuntime>(|runtime| {
runtime.add_function(
String::from("my_print"),
|In((x,)): In<(String,)>| {
println!("my_print: '{}'", x);
},
);
})
.add_systems(Startup,|mut commands: Commands, asset_server: Res<AssetServer>| {
commands.spawn(Script::<LuaScript>::new(asset_server.load("script.lua")));
})
.run();
commands.spawn(Script::new(asset_server.load("script.rhai")));
});
```
You should then see `my_print: 'Hello world!'` printed in your console.
### Provided examples
You can also try running provided examples by cloning this repository and running `cargo run --example <example_name>_<language_name>`. For example:
You can also try running provided examples by cloning this repository and running `cargo run --example <example_name>`. For example:
```bash
cargo run --example hello_world_lua
cargo run --example hello_world
```
The examples live in `examples` directory and their corresponding scripts live in `assets/examples` directory within the repository.
### Bevy compatibility
| bevy version | bevy_scriptum version |
|--------------|-----------------------|
| 0.16 | 0.8-0.9 |
| 0.15 | 0.7 |
| 0.14 | 0.6 |
| 0.13 | 0.4-0.5 |
| 0.12 | 0.3 |
| 0.11 | 0.2 |
| 0.10 | 0.1 |
|--------------|----------------------|
| 0.11 | 0.2 |
| 0.10 | 0.1 |
### Promises - getting return values from scripts
Every function called from script returns a promise that you can call `:and_then` with a callback function on. This callback function will be called when the promise is resolved, and will be passed the return value of the function called from script. For example:
Every function called from script returns a promise that you can call `.then` with a callback function on. This callback function will be called when the promise is resolved, and will be passed the return value of the function called from script. For example:
```lua
get_player_name():and_then(function(name)
print(name)
end)
```rhai
get_player_name().then(|name| {
print(name);
});
```
which will print out `John` when used with following exposed function:
```rust
use bevy::prelude::*;
use bevy_scriptum::prelude::*;
use bevy_scriptum::runtimes::lua::prelude::*;
App::new()
.add_plugins(DefaultPlugins)
.add_scripting::<LuaRuntime>(|runtime| {
runtime.add_function(String::from("get_player_name"), || String::from("John"));
});
````
## Access entity from script
### Access entity from script
A variable called `entity` is automatically available to all scripts - it represents bevy entity that the `Script` component is attached to.
It exposes `index` property that returns bevy entity index.
It exposes `.index()` method that returns bevy entity index.
It is useful for accessing entity's components from scripts.
It can be used in the following way:
```lua
print("Current entity index: " .. entity.index)
```rhai
print("Current entity index: " + entity.index());
```
`entity` variable is currently not available within promise callbacks.
### Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.

View file

@ -7,7 +7,8 @@ currently being supported with security updates.
| Version | Supported |
| ------- | ------------------ |
| 0.9 | :white_check_mark: |
| 0.1 | :x: |
| 0.2 | :white_check_mark: |
## Reporting a Vulnerability

View file

@ -1,3 +1,3 @@
// entity is a global variable that is set to the entity that is currently being processed,
// it is automatically available in all scripts
print("Current entity index: " + entity.index);
print("Current entity index: " + entity.index());

View file

@ -1,13 +0,0 @@
local my_state = {
iterations = 0,
}
function on_update()
my_state.iterations = my_state.iterations + 1;
print("on_update called " .. my_state.iterations .. " times")
if my_state.iterations >= 10 then
print("calling quit");
quit();
end
end

View file

@ -1,7 +0,0 @@
-- entity is a global variable that is set to the entity that is currently being processed,
-- it is automatically available in all scripts
-- get name of the entity
get_name(entity):and_then(function(name)
print(name)
end)

View file

@ -1,4 +0,0 @@
-- Create a new instance of MyType
my_type = MyType();
-- Call registered method
print(my_type:my_method())

View file

@ -1 +0,0 @@
print_player_names()

View file

@ -1,3 +0,0 @@
-- entity is a global variable that is set to the entity that is currently being processed,
-- it is automatically available in all scripts
print("Current entity index: " .. entity.index)

View file

@ -1,4 +0,0 @@
fun_with_string_param("hello")
fun_with_i64_param(5)
fun_with_multiple_params(5, "hello")
fun_with_i64_and_array_param(5, { 1, 2, "third element" })

View file

@ -1,3 +0,0 @@
function get_value()
return 42
end

View file

@ -1 +0,0 @@
hello_bevy();

View file

@ -1 +0,0 @@
hello_from_plugin_a()

View file

@ -1 +0,0 @@
hello_from_plugin_b_with_parameters("hello", 42)

View file

@ -1,3 +0,0 @@
get_player_name():and_then(function(name)
print(name)
end);

View file

@ -1 +0,0 @@
spawn_entity();

View file

@ -1,3 +0,0 @@
fn get_value() {
42
}

View file

@ -1 +0,0 @@
hello_from_plugin_a();

View file

@ -1 +0,0 @@
hello_from_plugin_b_with_parameters("hello", 42);

View file

@ -1,13 +0,0 @@
$my_state = {
iterations: 0,
}
def on_update
$my_state[:iterations] += 1
puts("on_update called #{$my_state[:iterations]} times")
if $my_state[:iterations] >= 10
print("calling quit");
quit()
end
end

View file

@ -1,3 +0,0 @@
get_name(Bevy::Entity.current).and_then do |name|
puts(name)
end

View file

@ -1,4 +0,0 @@
# Create a new instance of MyType
my_type = MyType.new()
# Call registered method
puts(my_type.my_method)

View file

@ -1 +0,0 @@
print_player_names

View file

@ -1,2 +0,0 @@
# Bevy::Entity.current can be used to access the entity that is currently being processed
puts("Current entity index: #{Bevy::Entity.current.index}")

View file

@ -1,4 +0,0 @@
fun_with_string_param("hello")
fun_with_i64_param(5)
fun_with_multiple_params(5, "hello")
fun_with_i64_and_array_param(5, [1, 2, "third element"])

View file

@ -1,3 +0,0 @@
def get_value
42
end

View file

@ -1 +0,0 @@
hello_bevy()

View file

@ -1 +0,0 @@
hello_from_plugin_a

View file

@ -1 +0,0 @@
hello_from_plugin_b_with_parameters("hello", 42)

View file

@ -1,3 +0,0 @@
get_player_name.and_then do |name|
puts name
end

View file

@ -1 +0,0 @@
spawn_entity()

View file

@ -1,3 +0,0 @@
function test_func()
print("abc" + 5)
end

View file

@ -1,7 +0,0 @@
State = {
called_with = nil
}
function test_func(x)
called_with = x
end

View file

@ -1,3 +0,0 @@
function test_func()
rust_func(entity.index)
end

View file

@ -1,5 +0,0 @@
index = entity.index
function test_func()
rust_func(index)
end

View file

@ -1,2 +0,0 @@
mark_called()
error()

View file

@ -1,3 +0,0 @@
function test_func()
rust_func(entity)
end

View file

@ -1,3 +0,0 @@
function test_func()
rust_func(Vec3(1.5, 2.5, -3.5))
end

View file

@ -1,6 +0,0 @@
function test_func(vec3)
assert(vec3.x == 1.5)
assert(vec3.y == 2.5)
assert(vec3.z == -3.5)
mark_success()
end

View file

@ -1,5 +0,0 @@
function test_func()
rust_func():and_then(function(x)
print("abc" + 5)
end)
end

View file

@ -1,9 +0,0 @@
State = {
x = nil
}
function test_func()
rust_func():and_then(function(x)
State.x = x
end)
end

View file

@ -1,3 +0,0 @@
function test_func()
rust_func()
end

View file

@ -1,3 +0,0 @@
function test_func()
rust_func(5, "test")
end

View file

@ -1,3 +0,0 @@
function test_func()
rust_func(5)
end

View file

@ -1,7 +0,0 @@
State = {
times_called = 0
}
function test_func()
State.times_called = State.times_called + 1;
end

View file

@ -1,9 +0,0 @@
State = {
a_value = nil,
b_value = nil
}
function test_func(a, b)
State.a_value = a
State.b_value = b
end

View file

@ -1,7 +0,0 @@
State = {
a_value = nil
}
function test_func(a)
State.a_value = a
end

View file

@ -1,3 +0,0 @@
function test_func()
spawn_entity()
end

View file

@ -1,3 +0,0 @@
fn test_func() {
print("abc" * 5)
}

View file

@ -1,2 +0,0 @@
fn test_func(x) {
}

View file

@ -1,3 +0,0 @@
fn test_func() {
rust_func(entity.index);
}

View file

@ -1,5 +0,0 @@
let index = entity.index;
fn test_func() {
rust_func(index);
}

View file

@ -1,2 +0,0 @@
mark_called();
throw();

View file

@ -1,3 +0,0 @@
fn test_func() {
rust_func(entity);
}

View file

@ -1,3 +0,0 @@
fn test_func() {
rust_func(new_vec3(1.5, 2.5, -3.5));
}

View file

@ -1,7 +0,0 @@
fn test_func(vec3) {
if type_of(vec3) != "Vec3" { throw() }
if vec3.x != 1.5 { throw() }
if vec3.y != 2.5 { throw() }
if vec3.z != -3.5 { throw() }
mark_success();
}

View file

@ -1,5 +0,0 @@
fn test_func() {
rust_func().then(|x| {
print("abc" * 5)
})
}

View file

@ -1,9 +0,0 @@
let state = #{
x: 0
};
fn test_func() {
rust_func().then(|x| {
state.x = x;
})
}

View file

@ -1,3 +0,0 @@
fn test_func() {
rust_func();
}

View file

@ -1,3 +0,0 @@
fn test_func() {
rust_func(5, "test");
}

View file

@ -1,3 +0,0 @@
fn test_func() {
rust_func(5);
}

View file

@ -1,7 +0,0 @@
let state = #{
times_called: 0
};
fn test_func() {
state.times_called += 1;
}

View file

@ -1,9 +0,0 @@
let state = #{
a_value: (),
b_value: ()
};
fn test_func(a, b) {
state.a_value = a;
state.b_value = b;
}

View file

@ -1,7 +0,0 @@
let state = #{
a_value: ()
};
fn test_func(a) {
state.a_value = a
}

View file

@ -1,3 +0,0 @@
fn test_func() {
spawn_entity()
}

View file

@ -1,3 +0,0 @@
def test_func
raise
end

View file

@ -1,7 +0,0 @@
$state = {
'called_with' => nil
}
def test_func(val)
$state['called_with'] = val
end

View file

@ -1,3 +0,0 @@
def test_func
rust_func(Bevy::Entity.current.index)
end

View file

@ -1,5 +0,0 @@
$index = Bevy::Entity.current.index
def test_func
rust_func($index)
end

View file

@ -1,2 +0,0 @@
mark_called
raise

View file

@ -1,3 +0,0 @@
def test_func
rust_func(Bevy::Entity.current)
end

View file

@ -1,3 +0,0 @@
def test_func
rust_func(Bevy::Vec3.new(1.5, 2.5, -3.5))
end

View file

@ -1,7 +0,0 @@
def test_func(vec3)
raise unless vec3.is_a?(Bevy::Vec3)
raise unless vec3.x == 1.5
raise unless vec3.y == 2.5
raise unless vec3.z == -3.5
mark_success
end

View file

@ -1,5 +0,0 @@
def test_func
rust_func.and_then do |x|
raise
end
end

View file

@ -1,9 +0,0 @@
$state = {
'x' => nil
}
def test_func
rust_func.and_then do |x|
$state['x'] = x
end
end

View file

@ -1,3 +0,0 @@
def test_func
rust_func
end

View file

@ -1,3 +0,0 @@
def test_func
rust_func(5, 'test')
end

View file

@ -1,3 +0,0 @@
def test_func
rust_func(5)
end

View file

@ -1,7 +0,0 @@
$state = {
'times_called' => 0
}
def test_func
$state['times_called'] += 1
end

View file

@ -1,9 +0,0 @@
$state = {
'a_value' => nil,
'b_value' => nil
}
def test_func(a, b)
$state['a_value'] = a
$state['b_value'] = b
end

View file

@ -1,7 +0,0 @@
$state = {
'a_value' => nil
}
def test_func(a)
$state['a_value'] = a
end

View file

@ -1,3 +0,0 @@
def test_func
spawn_entity
end

3
book/.gitignore vendored
View file

@ -1,3 +0,0 @@
book
doctest_cache
target

2498
book/Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,7 +0,0 @@
[package]
name = "bevy_scriptum_book"
publish = false
edition = "2024"
[dependencies]
bevy_scriptum = { path = "../", features = ["ruby", "lua", "rhai"] }

View file

@ -1,6 +0,0 @@
[book]
authors = ["Jaroslaw Konik"]
language = "en"
multilingual = false
src = "src"
title = "bevy_scriptum"

View file

@ -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

View file

@ -1,30 +0,0 @@
# Summary
- [Introduction](./introduction.md)
- [Runtimes](./runtimes.md)
- [Lua](./lua/lua.md)
- [Installation](./lua/installation.md)
- [Hello World](./lua/hello_world.md)
- [Spawning scripts](./lua/spawning_scripts.md)
- [Calling Rust from Lua](./lua/calling_rust_from_script.md)
- [Calling Lua from Rust](./lua/calling_script_from_rust.md)
- [Interacting with bevy in callbacks](./lua/interacting_with_bevy.md)
- [Builtin types](./lua/builtin_types.md)
- [Builtin variables](./lua/builtin_variables.md)
- [Ruby](./ruby/ruby.md)
- [Installation](./ruby/installation.md)
- [Hello World](./ruby/hello_world.md)
- [Spawning scripts](./ruby/spawning_scripts.md)
- [Calling Rust from Ruby](./ruby/calling_rust_from_script.md)
- [Calling Ruby from Rust](./ruby/calling_script_from_rust.md)
- [Interacting with bevy in callbacks](./ruby/interacting_with_bevy.md)
- [Builtin types](./ruby/builtin_types.md)
- [Rhai](./rhai/rhai.md)
- [Installation](./rhai/installation.md)
- [Hello World(TBD)]()
- [Multiple plugins](./multiple_plugins.md)
- [Multiple runtimes(TBD)]()
- [Implementing custom runtimes(TBD)]()
- [Workflow](./workflow/workflow.md)
- [Live-reload](./workflow/live_reload.md)
- [Bevy support matrix](./bevy_support_matrix.md)

Some files were not shown because too many files have changed in this diff Show more