-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |