Compare commits
45 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa70abac23 | ||
| 41d0fd57f3 | |||
|
|
e430795dce | ||
|
|
c6bdfb1400 | ||
|
|
450962b1d0 | ||
|
|
53479f94b5 | ||
|
|
f2bb079c60 | ||
| 56fd44062c | |||
|
|
297bffd060 | ||
|
|
2c82a2fa0e | ||
|
|
ec84d9e740 | ||
|
|
f9e872e111 | ||
|
|
a718aa7ce6 | ||
|
|
be8a80519d | ||
|
|
f85dbcffe2 | ||
|
|
182f26e273 | ||
|
|
7488de076b | ||
|
|
eaffce5c6d | ||
| 0766aef930 | |||
| 7a8721f78f | |||
| a2ddb9b5c1 | |||
| 94b64f37a8 | |||
| 3887e544b1 | |||
| 6a30384aef | |||
|
|
6726e40768 | ||
| 7846b556ca | |||
|
|
407da8d608 | ||
|
|
60984220a0 | ||
|
|
928f5437fc | ||
|
|
8997159e2f | ||
|
|
6f35089693 | ||
| db3258e832 | |||
|
|
bed58a9c2b | ||
|
|
4458ef2daf | ||
|
|
57459462d5 | ||
| 025cad413d | |||
| ab6cfe825e | |||
|
|
bce2e55d0d | ||
|
|
db6c9381d0 | ||
|
|
30a2acd121 | ||
|
|
d064450b78 | ||
|
|
be630f9b86 | ||
|
|
d574104412 | ||
| b4859e817e | |||
| be7fa2e48b |
191 changed files with 8997 additions and 731 deletions
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: [jarkonik]
|
||||||
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Desktop (please complete the following information):**
|
||||||
|
- OS: [e.g. iOS]
|
||||||
|
- Browser [e.g. chrome, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Smartphone (please complete the following information):**
|
||||||
|
- Device: [e.g. iPhone6]
|
||||||
|
- OS: [e.g. iOS8.1]
|
||||||
|
- Browser [e.g. stock browser, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
10
.github/ISSUE_TEMPLATE/custom.md
vendored
Normal file
10
.github/ISSUE_TEMPLATE/custom.md
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
name: Custom issue template
|
||||||
|
about: Describe this issue template's purpose here.
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
54
.github/workflows/book.yml
vendored
Normal file
54
.github/workflows/book.yml
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
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/
|
||||||
38
.github/workflows/deploy_book.yml
vendored
Normal file
38
.github/workflows/deploy_book.yml
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
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
|
||||||
51
.github/workflows/rust.yml
vendored
51
.github/workflows/rust.yml
vendored
|
|
@ -2,27 +2,48 @@ name: Rust
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main" ]
|
branches: ["main"]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: ["main"]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: -D warnings
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Clippy
|
- name: Cache Ruby
|
||||||
run: cargo clippy --verbose -- -D warnings
|
id: cache-ruby
|
||||||
- name: Build
|
uses: actions/cache@v4
|
||||||
run: cargo build --verbose
|
with:
|
||||||
- name: Run tests
|
path: rubies
|
||||||
run: cargo test --verbose
|
key: ${{ runner.os }}-ruby
|
||||||
- name: Install cargo-examples
|
- name: Install Ruby
|
||||||
run: cargo install cargo-examples
|
if: steps.cache-ruby.outputs.cache-hit != 'true'
|
||||||
- name: Run all examples
|
env:
|
||||||
run: cargo examples
|
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
|
||||||
|
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
/target
|
/target
|
||||||
/Cargo.lock
|
/Cargo.lock
|
||||||
.vscode
|
.vscode
|
||||||
|
.nvim.lua
|
||||||
|
|
|
||||||
128
CODE_OF_CONDUCT.md
Normal file
128
CODE_OF_CONDUCT.md
Normal file
|
|
@ -0,0 +1,128 @@
|
||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
We as members, contributors, and leaders pledge to make participation in our
|
||||||
|
community a harassment-free experience for everyone, regardless of age, body
|
||||||
|
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||||
|
identity and expression, level of experience, education, socio-economic status,
|
||||||
|
nationality, personal appearance, race, religion, or sexual identity
|
||||||
|
and orientation.
|
||||||
|
|
||||||
|
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||||
|
diverse, inclusive, and healthy community.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to a positive environment for our
|
||||||
|
community include:
|
||||||
|
|
||||||
|
* Demonstrating empathy and kindness toward other people
|
||||||
|
* Being respectful of differing opinions, viewpoints, and experiences
|
||||||
|
* Giving and gracefully accepting constructive feedback
|
||||||
|
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||||
|
and learning from the experience
|
||||||
|
* Focusing on what is best not just for us as individuals, but for the
|
||||||
|
overall community
|
||||||
|
|
||||||
|
Examples of unacceptable behavior include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery, and sexual attention or
|
||||||
|
advances of any kind
|
||||||
|
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or email
|
||||||
|
address, without their explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a
|
||||||
|
professional setting
|
||||||
|
|
||||||
|
## Enforcement Responsibilities
|
||||||
|
|
||||||
|
Community leaders are responsible for clarifying and enforcing our standards of
|
||||||
|
acceptable behavior and will take appropriate and fair corrective action in
|
||||||
|
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||||
|
or harmful.
|
||||||
|
|
||||||
|
Community leaders have the right and responsibility to remove, edit, or reject
|
||||||
|
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||||
|
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||||
|
decisions when appropriate.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies within all community spaces, and also applies when
|
||||||
|
an individual is officially representing the community in public spaces.
|
||||||
|
Examples of representing our community include using an official e-mail address,
|
||||||
|
posting via an official social media account, or acting as an appointed
|
||||||
|
representative at an online or offline event.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
|
reported to the community leaders responsible for enforcement at
|
||||||
|
yellow.egg4414@fastmail.com.
|
||||||
|
All complaints will be reviewed and investigated promptly and fairly.
|
||||||
|
|
||||||
|
All community leaders are obligated to respect the privacy and security of the
|
||||||
|
reporter of any incident.
|
||||||
|
|
||||||
|
## Enforcement Guidelines
|
||||||
|
|
||||||
|
Community leaders will follow these Community Impact Guidelines in determining
|
||||||
|
the consequences for any action they deem in violation of this Code of Conduct:
|
||||||
|
|
||||||
|
### 1. Correction
|
||||||
|
|
||||||
|
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||||
|
unprofessional or unwelcome in the community.
|
||||||
|
|
||||||
|
**Consequence**: A private, written warning from community leaders, providing
|
||||||
|
clarity around the nature of the violation and an explanation of why the
|
||||||
|
behavior was inappropriate. A public apology may be requested.
|
||||||
|
|
||||||
|
### 2. Warning
|
||||||
|
|
||||||
|
**Community Impact**: A violation through a single incident or series
|
||||||
|
of actions.
|
||||||
|
|
||||||
|
**Consequence**: A warning with consequences for continued behavior. No
|
||||||
|
interaction with the people involved, including unsolicited interaction with
|
||||||
|
those enforcing the Code of Conduct, for a specified period of time. This
|
||||||
|
includes avoiding interactions in community spaces as well as external channels
|
||||||
|
like social media. Violating these terms may lead to a temporary or
|
||||||
|
permanent ban.
|
||||||
|
|
||||||
|
### 3. Temporary Ban
|
||||||
|
|
||||||
|
**Community Impact**: A serious violation of community standards, including
|
||||||
|
sustained inappropriate behavior.
|
||||||
|
|
||||||
|
**Consequence**: A temporary ban from any sort of interaction or public
|
||||||
|
communication with the community for a specified period of time. No public or
|
||||||
|
private interaction with the people involved, including unsolicited interaction
|
||||||
|
with those enforcing the Code of Conduct, is allowed during this period.
|
||||||
|
Violating these terms may lead to a permanent ban.
|
||||||
|
|
||||||
|
### 4. Permanent Ban
|
||||||
|
|
||||||
|
**Community Impact**: Demonstrating a pattern of violation of community
|
||||||
|
standards, including sustained inappropriate behavior, harassment of an
|
||||||
|
individual, or aggression toward or disparagement of classes of individuals.
|
||||||
|
|
||||||
|
**Consequence**: A permanent ban from any sort of public interaction within
|
||||||
|
the community.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||||
|
version 2.0, available at
|
||||||
|
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||||
|
|
||||||
|
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||||
|
enforcement ladder](https://github.com/mozilla/diversity).
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
|
For answers to common questions about this code of conduct, see the FAQ at
|
||||||
|
https://www.contributor-covenant.org/faq. Translations are available at
|
||||||
|
https://www.contributor-covenant.org/translations.
|
||||||
4
CONTRIBUTING.md
Normal file
4
CONTRIBUTING.md
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
1. Fork.
|
||||||
|
2. Create a pull request.
|
||||||
|
3. Make sure all automated checks pass.
|
||||||
|
|
||||||
217
Cargo.toml
217
Cargo.toml
|
|
@ -1,14 +1,217 @@
|
||||||
[package]
|
[package]
|
||||||
name = "bevy_scriptum"
|
name = "bevy_scriptum"
|
||||||
version = "0.1.0"
|
authors = ["Jaroslaw Konik <konikjar@gmail.com>"]
|
||||||
edition = "2021"
|
version = "0.9.1"
|
||||||
|
edition = "2024"
|
||||||
|
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"
|
||||||
|
repository = "https://github.com/jarkonik/bevy_scriptum"
|
||||||
|
keywords = ["bevy", "lua", "scripting", "game", "script"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
[features]
|
||||||
|
lua = ["dep:mlua", "mlua/luajit"]
|
||||||
|
rhai = ["dep:rhai"]
|
||||||
|
ruby = ["dep:magnus", "dep:rb-sys"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { default-features = false, version = "0.10.1", features = [
|
bevy = { default-features = false, version = "0.16", features = ["bevy_asset", "bevy_log"] }
|
||||||
"bevy_asset",
|
|
||||||
] }
|
|
||||||
serde = "1.0.162"
|
serde = "1.0.162"
|
||||||
rhai = { version = "1.14.0", features = ["sync", "internals", "unchecked"] }
|
rhai = { version = "1.14.0", features = [
|
||||||
|
"sync",
|
||||||
|
"internals",
|
||||||
|
"unchecked",
|
||||||
|
], optional = true }
|
||||||
thiserror = "1.0.40"
|
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"] }
|
||||||
|
|
|
||||||
188
README.md
188
README.md
|
|
@ -1,34 +1,47 @@
|
||||||
# bevy_scriptum 📜
|
# bevy_scriptum 📜
|
||||||
|
|
||||||
⚠️ **Pre-release, alpha version**: API is bound to change, bugs are to be expected.
|

|
||||||
|
|
||||||
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.
|
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.
|
||||||
Currently, only [Rhai](https://rhai.rs/) is supported, but more languages may be added in the future.
|
### Supported scripting languages/runtimes
|
||||||
|
|
||||||
It's main advantages include:
|
| 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:
|
||||||
- low-boilerplate
|
- low-boilerplate
|
||||||
- easy to use
|
- easy to use
|
||||||
- asynchronicity with a promise-based API
|
- asynchronicity with a promise-based API
|
||||||
- flexibility
|
- flexibility
|
||||||
- hot-reloading
|
- hot-reloading
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
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
|
```rust
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
.add_script_function(String::from("hello_bevy"), || {
|
runtime.add_function(String::from("hello_bevy"), || {
|
||||||
println!("hello bevy, called from script");
|
println!("hello bevy, called from script");
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.run();
|
||||||
```
|
```
|
||||||
And you can call them in your scripts like this:
|
And you can call them in your scripts like this:
|
||||||
```rhai
|
```lua
|
||||||
hello_bevy();
|
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:
|
||||||
|
|
@ -36,42 +49,47 @@ Every callback function that you expose to the scripting language is also a Bevy
|
||||||
```rust
|
```rust
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Player;
|
struct Player;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
.add_script_function(
|
runtime.add_function(
|
||||||
String::from("print_player_names"),
|
String::from("print_player_names"),
|
||||||
|players: Query<&Name, With<Player>>| {
|
|players: Query<&Name, With<Player>>| {
|
||||||
for player in &players {
|
for player in &players {
|
||||||
println!("player name: {}", player);
|
println!("player name: {}", player);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
})
|
||||||
|
.run();
|
||||||
```
|
```
|
||||||
|
|
||||||
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
|
```rust
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
use rhai::ImmutableString;
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
.add_script_function(
|
runtime.add_function(
|
||||||
String::from("fun_with_string_param"),
|
String::from("fun_with_string_param"),
|
||||||
|In((x,)): In<(ImmutableString,)>| {
|
|In((x,)): In<(String,)>| {
|
||||||
println!("called with string: '{}'", x);
|
println!("called with string: '{}'", x);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
})
|
||||||
|
.run();
|
||||||
```
|
```
|
||||||
which you can then call in your script like this:
|
which you can then call in your script like this:
|
||||||
```rhai
|
```lua
|
||||||
fun_with_string_param("Hello world!");
|
fun_with_string_param("Hello world!")
|
||||||
```
|
```
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
@ -80,94 +98,118 @@ Add the following to your `Cargo.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy_scriptum = "0.1"
|
bevy_scriptum = { version = "0.9", features = ["lua"] }
|
||||||
```
|
```
|
||||||
|
|
||||||
or execute `cargo add bevy_scriptum` from your project directory.
|
or execute `cargo add bevy_scriptum --features lua` 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_plugin(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:
|
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
|
```rust
|
||||||
use rhai::ImmutableString;
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::prelude::*;
|
use bevy_scriptum::prelude::*;
|
||||||
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(ScriptingPlugin::default())
|
.add_scripting::<LuaRuntime>(|runtime| {
|
||||||
.add_script_function(
|
runtime.add_function(
|
||||||
String::from("my_print"),
|
String::from("my_print"),
|
||||||
|In((x,)): In<(ImmutableString,)>| {
|
|In((x,)): In<(String,)>| {
|
||||||
println!("my_print: '{}'", x);
|
println!("my_print: '{}'", x);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
})
|
||||||
|
.run();
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you can create a script file in `assets` directory called `script.rhai` that calls this function:
|
Then you can create a script file in `assets` directory called `script.lua` that calls this function:
|
||||||
|
|
||||||
```rhai
|
```lua
|
||||||
my_print("Hello world!");
|
my_print("Hello world!")
|
||||||
```
|
```
|
||||||
|
|
||||||
And spawn a `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
|
```rust
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_scriptum::Script;
|
use bevy_scriptum::prelude::*;
|
||||||
|
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_startup_system(|mut commands: Commands, asset_server: Res<AssetServer>| {
|
.add_plugins(DefaultPlugins)
|
||||||
commands.spawn(Script::new(asset_server.load("script.rhai")));
|
.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();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You should then see `my_print: 'Hello world!'` printed in your console.
|
||||||
|
|
||||||
### Provided examples
|
### Provided examples
|
||||||
|
|
||||||
You can also try running provided examples by cloning this repository and running `cargo run --example <example_name>`. For example:
|
You can also try running provided examples by cloning this repository and running `cargo run --example <example_name>_<language_name>`. For example:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo run --example hello_world
|
cargo run --example hello_world_lua
|
||||||
```
|
```
|
||||||
The examples live in `examples` directory and their corresponding scripts live in `assets/examples` directory within the repository.
|
The examples live in `examples` directory and their corresponding scripts live in `assets/examples` directory within the repository.
|
||||||
|
|
||||||
### Bevy compatibility
|
### Bevy compatibility
|
||||||
|
|
||||||
| bevy version | bevy_scriptum version |
|
| bevy version | bevy_scriptum version |
|
||||||
|--------------|----------------------|
|
|--------------|-----------------------|
|
||||||
| 0.10 | 0.1 |
|
| 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 |
|
||||||
|
|
||||||
### Promises - getting return values from scripts
|
### Promises - getting return values from scripts
|
||||||
|
|
||||||
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:
|
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:
|
||||||
|
|
||||||
```rhai
|
```lua
|
||||||
get_player_name().then(|name| {
|
get_player_name():and_then(function(name)
|
||||||
print(name);
|
print(name)
|
||||||
});
|
end)
|
||||||
```
|
```
|
||||||
|
which will print out `John` when used with following exposed function:
|
||||||
|
|
||||||
### Access entity from script
|
```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
|
||||||
|
|
||||||
A variable called `entity` is automatically available to all scripts - it represents bevy entity that the `Script` component is attached to.
|
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:
|
||||||
```rhai
|
```lua
|
||||||
print("Current entity index: " + entity.index());
|
print("Current entity index: " .. entity.index)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`entity` variable is currently not available within promise callbacks.
|
||||||
|
|
||||||
### Contributing
|
### Contributing
|
||||||
|
|
||||||
Contributions are welcome! Feel free to open an issue or submit a pull request.
|
Contributions are welcome! Feel free to open an issue or submit a pull request.
|
||||||
|
|
|
||||||
14
SECURITY.md
Normal file
14
SECURITY.md
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
Use this section to tell people about which versions of your project are
|
||||||
|
currently being supported with security updates.
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| ------- | ------------------ |
|
||||||
|
| 0.9 | :white_check_mark: |
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
Vulnerabilities should be reported at konikjar@gmail.com
|
||||||
13
assets/examples/lua/call_function_from_rust.lua
Normal file
13
assets/examples/lua/call_function_from_rust.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
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
|
||||||
7
assets/examples/lua/current_entity.lua
Normal file
7
assets/examples/lua/current_entity.lua
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
-- 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)
|
||||||
4
assets/examples/lua/custom_type.lua
Normal file
4
assets/examples/lua/custom_type.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
-- Create a new instance of MyType
|
||||||
|
my_type = MyType();
|
||||||
|
-- Call registered method
|
||||||
|
print(my_type:my_method())
|
||||||
1
assets/examples/lua/ecs.lua
Normal file
1
assets/examples/lua/ecs.lua
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
print_player_names()
|
||||||
3
assets/examples/lua/entity_variable.lua
Normal file
3
assets/examples/lua/entity_variable.lua
Normal file
|
|
@ -0,0 +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)
|
||||||
4
assets/examples/lua/function_params.lua
Normal file
4
assets/examples/lua/function_params.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
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" })
|
||||||
3
assets/examples/lua/function_return_value.lua
Normal file
3
assets/examples/lua/function_return_value.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
function get_value()
|
||||||
|
return 42
|
||||||
|
end
|
||||||
1
assets/examples/lua/multiple_plugins_plugin_a.lua
Normal file
1
assets/examples/lua/multiple_plugins_plugin_a.lua
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
hello_from_plugin_a()
|
||||||
1
assets/examples/lua/multiple_plugins_plugin_b.lua
Normal file
1
assets/examples/lua/multiple_plugins_plugin_b.lua
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
hello_from_plugin_b_with_parameters("hello", 42)
|
||||||
3
assets/examples/lua/promises.lua
Normal file
3
assets/examples/lua/promises.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
get_player_name():and_then(function(name)
|
||||||
|
print(name)
|
||||||
|
end);
|
||||||
1
assets/examples/lua/side_effects.lua
Normal file
1
assets/examples/lua/side_effects.lua
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
spawn_entity();
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
// entity is a global variable that is set to the entity that is currently being processed,
|
// entity is a global variable that is set to the entity that is currently being processed,
|
||||||
// it is automatically available in all scripts
|
// it is automatically available in all scripts
|
||||||
print("Current entity index: " + entity.index());
|
print("Current entity index: " + entity.index);
|
||||||
3
assets/examples/rhai/function_return_value.rhai
Normal file
3
assets/examples/rhai/function_return_value.rhai
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn get_value() {
|
||||||
|
42
|
||||||
|
}
|
||||||
1
assets/examples/rhai/hello_world.rhai
Normal file
1
assets/examples/rhai/hello_world.rhai
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
hello_bevy();
|
||||||
1
assets/examples/rhai/multiple_plugins_plugin_a.rhai
Normal file
1
assets/examples/rhai/multiple_plugins_plugin_a.rhai
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
hello_from_plugin_a();
|
||||||
1
assets/examples/rhai/multiple_plugins_plugin_b.rhai
Normal file
1
assets/examples/rhai/multiple_plugins_plugin_b.rhai
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
hello_from_plugin_b_with_parameters("hello", 42);
|
||||||
1
assets/examples/rhai/side_effects.rhai
Normal file
1
assets/examples/rhai/side_effects.rhai
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
spawn_entity();
|
||||||
13
assets/examples/ruby/call_function_from_rust.rb
Normal file
13
assets/examples/ruby/call_function_from_rust.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
$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
|
||||||
3
assets/examples/ruby/current_entity.rb
Normal file
3
assets/examples/ruby/current_entity.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
get_name(Bevy::Entity.current).and_then do |name|
|
||||||
|
puts(name)
|
||||||
|
end
|
||||||
4
assets/examples/ruby/custom_type.rb
Normal file
4
assets/examples/ruby/custom_type.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Create a new instance of MyType
|
||||||
|
my_type = MyType.new()
|
||||||
|
# Call registered method
|
||||||
|
puts(my_type.my_method)
|
||||||
1
assets/examples/ruby/ecs.rb
Normal file
1
assets/examples/ruby/ecs.rb
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
print_player_names
|
||||||
2
assets/examples/ruby/entity_variable.rb
Normal file
2
assets/examples/ruby/entity_variable.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# Bevy::Entity.current can be used to access the entity that is currently being processed
|
||||||
|
puts("Current entity index: #{Bevy::Entity.current.index}")
|
||||||
4
assets/examples/ruby/function_params.rb
Normal file
4
assets/examples/ruby/function_params.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
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"])
|
||||||
3
assets/examples/ruby/function_return_value.rb
Normal file
3
assets/examples/ruby/function_return_value.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
def get_value
|
||||||
|
42
|
||||||
|
end
|
||||||
1
assets/examples/ruby/hello_world.rb
Normal file
1
assets/examples/ruby/hello_world.rb
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
hello_bevy()
|
||||||
1
assets/examples/ruby/multiple_plugins_plugin_a.rb
Normal file
1
assets/examples/ruby/multiple_plugins_plugin_a.rb
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
hello_from_plugin_a
|
||||||
1
assets/examples/ruby/multiple_plugins_plugin_b.rb
Normal file
1
assets/examples/ruby/multiple_plugins_plugin_b.rb
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
hello_from_plugin_b_with_parameters("hello", 42)
|
||||||
3
assets/examples/ruby/promises.rb
Normal file
3
assets/examples/ruby/promises.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
get_player_name.and_then do |name|
|
||||||
|
puts name
|
||||||
|
end
|
||||||
1
assets/examples/ruby/side_effects.rb
Normal file
1
assets/examples/ruby/side_effects.rb
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
spawn_entity()
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
function test_func()
|
||||||
|
print("abc" + 5)
|
||||||
|
end
|
||||||
7
assets/tests/lua/call_script_function_with_params.lua
Normal file
7
assets/tests/lua/call_script_function_with_params.lua
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
State = {
|
||||||
|
called_with = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_func(x)
|
||||||
|
called_with = x
|
||||||
|
end
|
||||||
3
assets/tests/lua/entity_variable.lua
Normal file
3
assets/tests/lua/entity_variable.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
function test_func()
|
||||||
|
rust_func(entity.index)
|
||||||
|
end
|
||||||
5
assets/tests/lua/entity_variable_eval.lua
Normal file
5
assets/tests/lua/entity_variable_eval.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
index = entity.index
|
||||||
|
|
||||||
|
function test_func()
|
||||||
|
rust_func(index)
|
||||||
|
end
|
||||||
2
assets/tests/lua/eval_that_causes_runtime_error.lua
Normal file
2
assets/tests/lua/eval_that_causes_runtime_error.lua
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
mark_called()
|
||||||
|
error()
|
||||||
3
assets/tests/lua/pass_entity_from_script.lua
Normal file
3
assets/tests/lua/pass_entity_from_script.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
function test_func()
|
||||||
|
rust_func(entity)
|
||||||
|
end
|
||||||
3
assets/tests/lua/pass_vec3_from_script.lua
Normal file
3
assets/tests/lua/pass_vec3_from_script.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
function test_func()
|
||||||
|
rust_func(Vec3(1.5, 2.5, -3.5))
|
||||||
|
end
|
||||||
6
assets/tests/lua/pass_vec3_to_script.lua
Normal file
6
assets/tests/lua/pass_vec3_to_script.lua
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
function test_func(vec3)
|
||||||
|
assert(vec3.x == 1.5)
|
||||||
|
assert(vec3.y == 2.5)
|
||||||
|
assert(vec3.z == -3.5)
|
||||||
|
mark_success()
|
||||||
|
end
|
||||||
5
assets/tests/lua/promise_runtime_error.lua
Normal file
5
assets/tests/lua/promise_runtime_error.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
function test_func()
|
||||||
|
rust_func():and_then(function(x)
|
||||||
|
print("abc" + 5)
|
||||||
|
end)
|
||||||
|
end
|
||||||
9
assets/tests/lua/return_via_promise.lua
Normal file
9
assets/tests/lua/return_via_promise.lua
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
State = {
|
||||||
|
x = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_func()
|
||||||
|
rust_func():and_then(function(x)
|
||||||
|
State.x = x
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
function test_func()
|
||||||
|
rust_func()
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
function test_func()
|
||||||
|
rust_func(5, "test")
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
function test_func()
|
||||||
|
rust_func(5)
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
State = {
|
||||||
|
times_called = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_func()
|
||||||
|
State.times_called = State.times_called + 1;
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
State = {
|
||||||
|
a_value = nil,
|
||||||
|
b_value = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_func(a, b)
|
||||||
|
State.a_value = a
|
||||||
|
State.b_value = b
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
State = {
|
||||||
|
a_value = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_func(a)
|
||||||
|
State.a_value = a
|
||||||
|
end
|
||||||
3
assets/tests/lua/side_effects.lua
Normal file
3
assets/tests/lua/side_effects.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
function test_func()
|
||||||
|
spawn_entity()
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn test_func() {
|
||||||
|
print("abc" * 5)
|
||||||
|
}
|
||||||
2
assets/tests/rhai/call_script_function_with_params.rhai
Normal file
2
assets/tests/rhai/call_script_function_with_params.rhai
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
fn test_func(x) {
|
||||||
|
}
|
||||||
3
assets/tests/rhai/entity_variable.rhai
Normal file
3
assets/tests/rhai/entity_variable.rhai
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn test_func() {
|
||||||
|
rust_func(entity.index);
|
||||||
|
}
|
||||||
5
assets/tests/rhai/entity_variable_eval.rhai
Normal file
5
assets/tests/rhai/entity_variable_eval.rhai
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
let index = entity.index;
|
||||||
|
|
||||||
|
fn test_func() {
|
||||||
|
rust_func(index);
|
||||||
|
}
|
||||||
2
assets/tests/rhai/eval_that_causes_runtime_error.rhai
Normal file
2
assets/tests/rhai/eval_that_causes_runtime_error.rhai
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
mark_called();
|
||||||
|
throw();
|
||||||
3
assets/tests/rhai/pass_entity_from_script.rhai
Normal file
3
assets/tests/rhai/pass_entity_from_script.rhai
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn test_func() {
|
||||||
|
rust_func(entity);
|
||||||
|
}
|
||||||
3
assets/tests/rhai/pass_vec3_from_script.rhai
Normal file
3
assets/tests/rhai/pass_vec3_from_script.rhai
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn test_func() {
|
||||||
|
rust_func(new_vec3(1.5, 2.5, -3.5));
|
||||||
|
}
|
||||||
7
assets/tests/rhai/pass_vec3_to_script.rhai
Normal file
7
assets/tests/rhai/pass_vec3_to_script.rhai
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
5
assets/tests/rhai/promise_runtime_error.rhai
Normal file
5
assets/tests/rhai/promise_runtime_error.rhai
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
fn test_func() {
|
||||||
|
rust_func().then(|x| {
|
||||||
|
print("abc" * 5)
|
||||||
|
})
|
||||||
|
}
|
||||||
9
assets/tests/rhai/return_via_promise.rhai
Normal file
9
assets/tests/rhai/return_via_promise.rhai
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
let state = #{
|
||||||
|
x: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
fn test_func() {
|
||||||
|
rust_func().then(|x| {
|
||||||
|
state.x = x;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn test_func() {
|
||||||
|
rust_func();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn test_func() {
|
||||||
|
rust_func(5, "test");
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn test_func() {
|
||||||
|
rust_func(5);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
let state = #{
|
||||||
|
times_called: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
fn test_func() {
|
||||||
|
state.times_called += 1;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
let state = #{
|
||||||
|
a_value: (),
|
||||||
|
b_value: ()
|
||||||
|
};
|
||||||
|
|
||||||
|
fn test_func(a, b) {
|
||||||
|
state.a_value = a;
|
||||||
|
state.b_value = b;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
let state = #{
|
||||||
|
a_value: ()
|
||||||
|
};
|
||||||
|
|
||||||
|
fn test_func(a) {
|
||||||
|
state.a_value = a
|
||||||
|
}
|
||||||
3
assets/tests/rhai/side_effects.rhai
Normal file
3
assets/tests/rhai/side_effects.rhai
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn test_func() {
|
||||||
|
spawn_entity()
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
def test_func
|
||||||
|
raise
|
||||||
|
end
|
||||||
7
assets/tests/ruby/call_script_function_with_params.rb
Normal file
7
assets/tests/ruby/call_script_function_with_params.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
$state = {
|
||||||
|
'called_with' => nil
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_func(val)
|
||||||
|
$state['called_with'] = val
|
||||||
|
end
|
||||||
3
assets/tests/ruby/entity_variable.rb
Normal file
3
assets/tests/ruby/entity_variable.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
def test_func
|
||||||
|
rust_func(Bevy::Entity.current.index)
|
||||||
|
end
|
||||||
5
assets/tests/ruby/entity_variable_eval.rb
Normal file
5
assets/tests/ruby/entity_variable_eval.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
$index = Bevy::Entity.current.index
|
||||||
|
|
||||||
|
def test_func
|
||||||
|
rust_func($index)
|
||||||
|
end
|
||||||
2
assets/tests/ruby/eval_that_causes_runtime_error.rb
Normal file
2
assets/tests/ruby/eval_that_causes_runtime_error.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
mark_called
|
||||||
|
raise
|
||||||
3
assets/tests/ruby/pass_entity_from_script.rb
Normal file
3
assets/tests/ruby/pass_entity_from_script.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
def test_func
|
||||||
|
rust_func(Bevy::Entity.current)
|
||||||
|
end
|
||||||
3
assets/tests/ruby/pass_vec3_from_script.rb
Normal file
3
assets/tests/ruby/pass_vec3_from_script.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
def test_func
|
||||||
|
rust_func(Bevy::Vec3.new(1.5, 2.5, -3.5))
|
||||||
|
end
|
||||||
7
assets/tests/ruby/pass_vec3_to_script.rb
Normal file
7
assets/tests/ruby/pass_vec3_to_script.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
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
|
||||||
5
assets/tests/ruby/promise_runtime_error.rb
Normal file
5
assets/tests/ruby/promise_runtime_error.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
def test_func
|
||||||
|
rust_func.and_then do |x|
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
end
|
||||||
9
assets/tests/ruby/return_via_promise.rb
Normal file
9
assets/tests/ruby/return_via_promise.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
$state = {
|
||||||
|
'x' => nil
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_func
|
||||||
|
rust_func.and_then do |x|
|
||||||
|
$state['x'] = x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
def test_func
|
||||||
|
rust_func
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
def test_func
|
||||||
|
rust_func(5, 'test')
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
def test_func
|
||||||
|
rust_func(5)
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
$state = {
|
||||||
|
'times_called' => 0
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_func
|
||||||
|
$state['times_called'] += 1
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
$state = {
|
||||||
|
'a_value' => nil,
|
||||||
|
'b_value' => nil
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_func(a, b)
|
||||||
|
$state['a_value'] = a
|
||||||
|
$state['b_value'] = b
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
$state = {
|
||||||
|
'a_value' => nil
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_func(a)
|
||||||
|
$state['a_value'] = a
|
||||||
|
end
|
||||||
3
assets/tests/ruby/side_effects.rb
Normal file
3
assets/tests/ruby/side_effects.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
def test_func
|
||||||
|
spawn_entity
|
||||||
|
end
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue