From 4b25bd0f1823d08cc68b5767aea65f1bf4c04580 Mon Sep 17 00:00:00 2001 From: Jaroslaw Konik Date: Tue, 27 May 2025 07:00:00 +0200 Subject: [PATCH] fix ruby docs --- book/justfile | 2 +- book/src/ruby/calling_rust_from_script.md | 25 ++++++++++++++++++----- book/src/ruby/calling_script_from_rust.md | 10 +++++++-- book/src/ruby/hello_world.md | 10 +++++++-- book/src/ruby/spawning_scripts.md | 6 ++++++ 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/book/justfile b/book/justfile index 53ffc65..a221a90 100644 --- a/book/justfile +++ b/book/justfile @@ -9,7 +9,7 @@ _test: test: build-deps _test test-watch: build-deps - watchexec --exts md just _test + watchexec --exts md -r just _test serve: mdbook serve diff --git a/book/src/ruby/calling_rust_from_script.md b/book/src/ruby/calling_rust_from_script.md index 3b7321e..de90227 100644 --- a/book/src/ruby/calling_rust_from_script.md +++ b/book/src/ruby/calling_rust_from_script.md @@ -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::*; diff --git a/book/src/ruby/calling_script_from_rust.md b/book/src/ruby/calling_script_from_rust.md index b543c2c..f572431 100644 --- a/book/src/ruby/calling_script_from_rust.md +++ b/book/src/ruby/calling_script_from_rust.md @@ -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::*; diff --git a/book/src/ruby/hello_world.md b/book/src/ruby/hello_world.md index 469f551..a271b2e 100644 --- a/book/src/ruby/hello_world.md +++ b/book/src/ruby/hello_world.md @@ -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::*; diff --git a/book/src/ruby/spawning_scripts.md b/book/src/ruby/spawning_scripts.md index 41a49b4..9cabc3b 100644 --- a/book/src/ruby/spawning_scripts.md +++ b/book/src/ruby/spawning_scripts.md @@ -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::` 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::*;