fix lua docs
This commit is contained in:
parent
4b25bd0f18
commit
97077338f9
7 changed files with 87 additions and 21 deletions
|
|
@ -24,7 +24,10 @@ bevy_scriptum's main advantages include:
|
|||
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 it.
|
||||
|
||||
All you need to do is register callbacks on your Bevy app like this:
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -47,7 +50,11 @@ 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:
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_ecs;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -73,7 +80,10 @@ fn main() {
|
|||
```
|
||||
|
||||
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,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -110,7 +120,10 @@ or execute `cargo add bevy_scriptum --features lua` from your project directory.
|
|||
|
||||
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,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -138,7 +151,10 @@ my_print("Hello world!")
|
|||
|
||||
And spawn an entity with attached `Script` component with a handle to a script source file:
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -183,7 +199,10 @@ end)
|
|||
```
|
||||
which will print out `John` when used with following exposed function:
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
|
|||
|
|
@ -20,14 +20,17 @@ bevy_scriptum provides following types that can be used in Lua:
|
|||
|
||||
### Example Lua usage
|
||||
|
||||
```
|
||||
```lua
|
||||
my_vec = Vec3(1, 2, 3)
|
||||
set_translation(entity, my_vec)
|
||||
```
|
||||
|
||||
### Example Rust usage
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -69,7 +72,10 @@ pass_to_rust(entity)
|
|||
|
||||
### Example Rust usage
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@
|
|||
To call a rust function from Lua first you need to register a function
|
||||
within Rust using builder pattern.
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -20,7 +23,10 @@ fn main() {
|
|||
|
||||
For example to register a function called `my_rust_func` you can do the following:
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -49,7 +55,10 @@ that implements `FromLua`.
|
|||
Since a registered callback function is a Bevy system, the parameters are passed
|
||||
to it as `In` struct with tuple, which has to be the first parameter of the closure.
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -68,7 +77,10 @@ fn main() {
|
|||
|
||||
To make it look nicer you can destructure the `In` struct.
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -97,7 +109,10 @@ Any registered rust function that returns a value will retrurn a promise when
|
|||
called within a script. By calling `:and_then` on the promise you can register
|
||||
a callback that will receive the value returned from Rust function.
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,10 @@ of the function to call, `LuaScriptData` that has been automatically
|
|||
attached to entity after an entity with script attached has been spawned
|
||||
and its script evaluated, the entity and optionally some arguments.
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -36,7 +39,10 @@ fn main() {}
|
|||
We can also pass some arguments by providing a tuple or `Vec` as the last
|
||||
`call_fn` argument.
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@ a create feature.
|
|||
|
||||
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,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -40,7 +43,10 @@ my_print("Hello world!")
|
|||
|
||||
And spawn an entity with attached `Script` component with a handle to a script source file:
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ That allows you to do anything you would do in a Bevy system.
|
|||
You could for example create a callback system function that prints names
|
||||
of all entities with `Player` component.
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_ecs;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -42,7 +46,11 @@ You can use functions that interact with Bevy entities and resources and
|
|||
take arguments at the same time. It could be used for example to mutate a
|
||||
component.
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_ecs;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -59,7 +67,7 @@ fn main() {
|
|||
runtime.add_function(
|
||||
String::from("hurt_player"),
|
||||
|In((hit_value,)): In<(i32,)>, mut players: Query<&mut Player>| {
|
||||
let mut player = players.single_mut();
|
||||
let mut player = players.single_mut().unwrap();
|
||||
player.health -= hit_value;
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ To spawn a Lua script you will need to get a handle to a script asset using
|
|||
bevy's `AssetServer`.
|
||||
|
||||
```rust
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -24,6 +27,9 @@ been attached to will get the `Script::<LuaScript>` component stripped and inste
|
|||
So to query scipted entities you could do something like:
|
||||
|
||||
```rust
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
|
|||
Loading…
Reference in a new issue