Skip to content

Commit 93f0cb2

Browse files
committed
update docs and check.sh
1 parent 5f1296f commit 93f0cb2

File tree

5 files changed

+99
-9
lines changed

5 files changed

+99
-9
lines changed

check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ CURRENT_DIR=$(basename "$PWD")
66
if [[ "$CURRENT_DIR" == "bevy_api_gen" ]]; then
77
cargo +nightly-2024-11-05 clippy --all-targets --message-format=json
88
else
9-
cargo clippy --workspace --all-targets --message-format=json --features="lua54 rhai teal rune bevy/file_watcher bevy/multi_threaded"
9+
cargo clippy --workspace --all-targets --message-format=json --features="lua54 rhai rune bevy/file_watcher bevy/multi_threaded"
1010
fi

docs/src/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Summary
22

3-
- [Chapter 1](./chapter_1.md)
3+
- [Installation](./installation.md)
4+
- [Managing Scripts](./managing-scripts.md)

docs/src/chapter_1.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/src/installation.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Installation
2+
3+
## Cargo
4+
5+
First you need to install the crate by adding this entry to your `Cargo.toml` dependencies list:
6+
7+
```toml
8+
bevy_mod_scripting = { version = "0.9.0", features = ["lua54"]}
9+
```
10+
11+
Choose the language features you wish enabled and add them to the features block.
12+
13+
14+
## Bevy Plugin
15+
16+
The next step is to add the BMS plugin to your application, on top of any other extras you want included in your app:
17+
18+
```rust,ignore
19+
app.add_plugins(LuaScriptingPlugin::<()>::default());
20+
```
21+
22+
The above is how you'd setup BMS for Lua, if you want to use another language, simply use a corresponding plugin from the integration crate.
23+
24+
25+
## Language Features
26+
27+
Each language supported by BMS can be switched-on via feature flag as below:
28+
29+
| Language | Feature Flag |
30+
| ---- | ---- |
31+
| Lua51 | lua51 |
32+
| Lua52 | lua54 |
33+
| Lua53 | lua53 |
34+
| Lua54 | lua54 |
35+
| Luajit | luajit |
36+
| Luajit52 | luajit52 |
37+
| Luau | luau |
38+
| Rhai | rhai |
39+
| Rune | rune |
40+
41+
## Extra Features
42+
43+
In order to fit as many use cases as possible, BMS allows you to disable a lot of its functionality.
44+
45+
By default all of the useful features are enabled, but you may disable them if you wish if you are only needing BMS for script lifecycle management, and want to populate the bindings yourself.
46+
47+
| Feature | Description |
48+
| ---- | ---- |
49+
| core_functions | If enabled, will enable all core functions, i.e. bevy integrations which let you interact with Bevy via reflection |
50+
| bevy_bindings | If enabled, populates the function registry with additiona automatically generated bevy bindings. This includes functions on `glam` and `bevy::ecs` types. These are useful but will slow down compilation considerably. |
51+

docs/src/managing-scripts.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Managing Scripts
2+
3+
Scripts live in the standard bevy `assets` directory. Loading a script means:
4+
- Parsing the script body
5+
- Creating or updating the resources which store script state
6+
- Assigning a name/id to the script so it can be referred to by the rest of the application.
7+
8+
## Loading
9+
BMS listens to `ScriptAsset` events and reacts accordingly. In order to load a script, all you need to do is request a handle to it via the asset server and store it somewhere.
10+
11+
Below is an example system which loads a script called `assets/my_script.lua` and stores the handle in a local system parameter:
12+
13+
```rust,ignore
14+
fn load_script(server: Res<AssetServer>, mut handle: Local<Handle<ScriptAsset>>) {
15+
let handle_ = server.load::<ScriptAsset>("my_script.lua");
16+
*handle = handle_;
17+
}
18+
```
19+
20+
In practice you will likely store this handle in a resource or component, when your load all the scripts necessary for your application.
21+
22+
23+
## Deleting scripts
24+
In order to delete a previously loaded script, you will need to issue a `DeleteScript` command like so:
25+
26+
```rust,ignore
27+
DeleteScript::new("my_script.lua".into())
28+
```
29+
30+
This will delete references to the script and remove any internal handles to the asset. You will also need to clean up any handles to the asset you hold in your application in order for the asset to be unloaded.
31+
32+
## Hot-loading scripts
33+
To enable hot-loading of assets, you need to enable the necessary bevy features as normal [see the bevy cheatbook for instructions](https://bevy-cheatbook.github.io/assets/hot-reload.html).
34+
35+
Assuming that hot-reloading is enabled for your app, any changes to script assets will automatically be picked up and the scripts re-loaded.
36+
37+
## Manually (re)loading scripts
38+
In order to manually re-load or load a script you can issue the `CreateOrUpdateScript` command:
39+
40+
```rust,ignore
41+
CreateOrUpdateScript::new("my_script.lua".into(), "print(\"hello world from new script body\")".into(), asset_handle)
42+
```
43+
44+
## Loading timeframe
45+
Scripts are processed via commands, so any asset events will be processed at the next command execution point running after BMS internal asset systems.

0 commit comments

Comments
 (0)