Ruby support #1

Open
jaroslaw wants to merge 165 commits from ruby into main
8 changed files with 29 additions and 25 deletions
Showing only changes of commit 2d2ba975bb - Show all commits

View file

@ -6,9 +6,9 @@ edition = "2024"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
readme = "README.md" readme = "README.md"
categories = ["game-development"] categories = ["game-development"]
description = "Plugin for Bevy engine that allows you to write some of your game logic in a scripting language" description = "Plugin for Bevy engine that allows you to write some of your game or application logic in a scripting language"
repository = "https://github.com/jarkonik/bevy_scriptum" repository = "https://github.com/jarkonik/bevy_scriptum"
keywords = ["bevy", "rhai", "scripting", "game", "gamedev"] keywords = ["bevy", "lua", "scripting", "game", "script"]
[features] [features]
lua = ["dep:mlua", "mlua/luajit"] lua = ["dep:mlua", "mlua/luajit"]

View file

@ -2,7 +2,7 @@
![demo](demo.gif) ![demo](demo.gif)
bevy_scriptum is a a plugin for [Bevy](https://bevyengine.org/) that allows you to write some of your game logic in a scripting language. bevy_scriptum is a a plugin for [Bevy](https://bevyengine.org/) that allows you to write some of your game or application logic in a scripting language.
Currently [Rhai](https://rhai.rs/) and [Lua](https://lua.org/) are supported, but more languages may be added in the future. Currently [Rhai](https://rhai.rs/) and [Lua](https://lua.org/) are supported, but more languages may be added in the future.
Everything you need to know to get started with using this library is contained in the Everything you need to know to get started with using this library is contained in the

View file

@ -1,6 +1,6 @@
# bevy_scriptum 📜 # bevy_scriptum 📜
bevy_scriptum is a a plugin for [Bevy](https://bevyengine.org/) that allows you to write some of your game logic in a scripting language. bevy_scriptum is a a plugin for [Bevy](https://bevyengine.org/) that allows you to write some of your game or application logic in a scripting language.
Currently [Rhai](https://rhai.rs/) and [Lua](https://lua.org/) are supported, but more languages may be added in the future. Currently [Rhai](https://rhai.rs/) and [Lua](https://lua.org/) are supported, but more languages may be added in the future.
API docs are available in [docs.rs](https://docs.rs/bevy_scriptum/latest/bevy_scriptum/) API docs are available in [docs.rs](https://docs.rs/bevy_scriptum/latest/bevy_scriptum/)

View file

@ -9,18 +9,18 @@ within bevy dependency in `Cargo.toml`
bevy = { version = "0.16", features = ["file_watcher"] } bevy = { version = "0.16", features = ["file_watcher"] }
``` ```
## Init-teardown pattern for game development ## Init-teardown pattern
It is useful to structure your game in a way that would allow making changes to It is useful to structure your application in a way that would allow making changes to
the scripting code without restarting the game. the scripting code without restarting the application.
A useful pattern is to hava three functions "init", "update" and "teardown". A useful pattern is to hava three functions "init", "update" and "teardown".
- "init" function will take care of starting the game(spawning the player, the level etc) - "init" function will take care of starting the application(spawning the player, the level etc)
- "update" function will run the main game logic - "update" function will run the main application logic
- "teardown" function will despawn all the entities so game starts at fresh state. - "teardown" function will despawn all the entities so application starts at fresh state.
This pattern is very easy to implement in bevy_scriptum. All you need is to define all needed functions This pattern is very easy to implement in bevy_scriptum. All you need is to define all needed functions
in script: in script:
@ -35,7 +35,7 @@ local function init()
player.entity = spawn_player() player.entity = spawn_player()
end end
-- game logic here, should be called in a bevy system using call_fn -- application logic here, should be called in a bevy system using call_fn
local function update() local function update()
(...) (...)
end end
@ -45,7 +45,7 @@ local function teardown()
despawn(player.entity) despawn(player.entity)
end end
-- call init to start the game, this will be called on each file-watcher script -- call init to start the application, this will be called on each file-watcher script
-- reload -- reload
init() init()
``` ```

View file

@ -4,7 +4,7 @@ use bevy_scriptum::runtimes::lua::prelude::*;
fn main() { fn main() {
App::new() App::new()
// This is just needed for headless console app, not needed for a regular bevy game // This is just needed for headless console app, not needed for a regular bevy application
// that uses a winit window // that uses a winit window
.set_runner(move |mut app: App| { .set_runner(move |mut app: App| {
loop { loop {

View file

@ -4,13 +4,15 @@ use bevy_scriptum::runtimes::rhai::prelude::*;
fn main() { fn main() {
App::new() App::new()
// This is just needed for headless console app, not needed for a regular bevy game // This is just needed for headless console app, not needed for a regular bevy application
// that uses a winit window // that uses a winit window
.set_runner(move |mut app: App| loop { .set_runner(move |mut app: App| {
loop {
app.update(); app.update();
if let Some(exit) = app.should_exit() { if let Some(exit) = app.should_exit() {
return exit; return exit;
} }
}
}) })
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_systems(Startup, startup) .add_systems(Startup, startup)

View file

@ -4,13 +4,15 @@ use bevy_scriptum::runtimes::ruby::prelude::*;
fn main() { fn main() {
App::new() App::new()
// This is just needed for headless console app, not needed for a regular bevy game // This is just needed for headless console app, not needed for a regular bevy application
// that uses a winit window // that uses a winit window
.set_runner(move |mut app: App| loop { .set_runner(move |mut app: App| {
loop {
app.update(); app.update();
if let Some(exit) = app.should_exit() { if let Some(exit) = app.should_exit() {
return exit; return exit;
} }
}
}) })
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_systems(Startup, startup) .add_systems(Startup, startup)

View file

@ -1,6 +1,6 @@
//! ![demo](demo.gif) //! ![demo](demo.gif)
//! //!
//! bevy_scriptum is a a plugin for [Bevy](https://bevyengine.org/) that allows you to write some of your game logic in a scripting language. //! bevy_scriptum is a a plugin for [Bevy](https://bevyengine.org/) that allows you to write some of your game or application logic in a scripting language.
//! Currently [Rhai](https://rhai.rs/) and [Lua](https://lua.org/) are supported, but more languages may be added in the future. //! Currently [Rhai](https://rhai.rs/) and [Lua](https://lua.org/) are supported, but more languages may be added in the future.
//! //!
//! Everything you need to know to get started with using this library is contained in the //! Everything you need to know to get started with using this library is contained in the
@ -15,7 +15,7 @@
//! - flexibility //! - flexibility
//! - hot-reloading //! - hot-reloading
//! //!
//! 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 your game. //! Scripts are separate files that can be hot-reloaded at runtime. This allows you to quickly iterate on your game or application logic without having to recompile your game.
//! //!
//! All you need to do is register callbacks on your Bevy app like this: //! All you need to do is register callbacks on your Bevy app like this:
//! ```no_run //! ```no_run