Skip to content

Commit

Permalink
update docs and check.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
makspll committed Jan 2, 2025
1 parent 5f1296f commit 93f0cb2
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 9 deletions.
2 changes: 1 addition & 1 deletion check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ CURRENT_DIR=$(basename "$PWD")
if [[ "$CURRENT_DIR" == "bevy_api_gen" ]]; then
cargo +nightly-2024-11-05 clippy --all-targets --message-format=json
else
cargo clippy --workspace --all-targets --message-format=json --features="lua54 rhai teal rune bevy/file_watcher bevy/multi_threaded"
cargo clippy --workspace --all-targets --message-format=json --features="lua54 rhai rune bevy/file_watcher bevy/multi_threaded"
fi
3 changes: 2 additions & 1 deletion docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Summary

- [Chapter 1](./chapter_1.md)
- [Installation](./installation.md)
- [Managing Scripts](./managing-scripts.md)
7 changes: 0 additions & 7 deletions docs/src/chapter_1.md

This file was deleted.

51 changes: 51 additions & 0 deletions docs/src/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Installation

## Cargo

First you need to install the crate by adding this entry to your `Cargo.toml` dependencies list:

```toml
bevy_mod_scripting = { version = "0.9.0", features = ["lua54"]}
```

Choose the language features you wish enabled and add them to the features block.


## Bevy Plugin

The next step is to add the BMS plugin to your application, on top of any other extras you want included in your app:

```rust,ignore
app.add_plugins(LuaScriptingPlugin::<()>::default());
```

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.


## Language Features

Each language supported by BMS can be switched-on via feature flag as below:

| Language | Feature Flag |
| ---- | ---- |
| Lua51 | lua51 |
| Lua52 | lua54 |
| Lua53 | lua53 |
| Lua54 | lua54 |
| Luajit | luajit |
| Luajit52 | luajit52 |
| Luau | luau |
| Rhai | rhai |
| Rune | rune |

## Extra Features

In order to fit as many use cases as possible, BMS allows you to disable a lot of its functionality.

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.

| Feature | Description |
| ---- | ---- |
| core_functions | If enabled, will enable all core functions, i.e. bevy integrations which let you interact with Bevy via reflection |
| 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. |

45 changes: 45 additions & 0 deletions docs/src/managing-scripts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Managing Scripts

Scripts live in the standard bevy `assets` directory. Loading a script means:
- Parsing the script body
- Creating or updating the resources which store script state
- Assigning a name/id to the script so it can be referred to by the rest of the application.

## Loading
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.

Below is an example system which loads a script called `assets/my_script.lua` and stores the handle in a local system parameter:

```rust,ignore
fn load_script(server: Res<AssetServer>, mut handle: Local<Handle<ScriptAsset>>) {
let handle_ = server.load::<ScriptAsset>("my_script.lua");
*handle = handle_;
}
```

In practice you will likely store this handle in a resource or component, when your load all the scripts necessary for your application.


## Deleting scripts
In order to delete a previously loaded script, you will need to issue a `DeleteScript` command like so:

```rust,ignore
DeleteScript::new("my_script.lua".into())
```

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.

## Hot-loading scripts
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).

Assuming that hot-reloading is enabled for your app, any changes to script assets will automatically be picked up and the scripts re-loaded.

## Manually (re)loading scripts
In order to manually re-load or load a script you can issue the `CreateOrUpdateScript` command:

```rust,ignore
CreateOrUpdateScript::new("my_script.lua".into(), "print(\"hello world from new script body\")".into(), asset_handle)
```

## Loading timeframe
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 comments on commit 93f0cb2

Please sign in to comment.