Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some code improvements #117

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
description = "Multi language scripting in Bevy"
repository = "https://github.com/makspll/bevy_mod_scripting"
homepage = "https://github.com/makspll/bevy_mod_scripting"
keywords = ["bevy", "gamedev", "scripting", "lua"]
keywords = ["bevy", "gamedev", "scripting", "lua", "rhai", "rune"]
categories = ["game-development"]
readme = "readme.md"
include = ["readme.md", "/src", "/examples", "/assets", "LICENSE"]
Expand All @@ -24,11 +24,12 @@ path = "src/lib.rs"
features = [
"lua",
"lua54",
"rhai",
"lua_script_api",
"rhai",
"rhai_script_api",
"teal",
"rune",
"rune_script_api",
"teal",
]

[features]
Expand All @@ -45,7 +46,7 @@ lua54 = ["bevy_mod_scripting_lua/lua54", "lua"]
luajit = ["bevy_mod_scripting_lua/luajit", "lua"]
luajit52 = ["bevy_mod_scripting_lua/luajit52", "lua"]

# optional
# lua optional
lua_script_api = ["bevy_script_api/lua"]
unsafe_lua_modules = ["bevy_mod_scripting_lua/unsafe_lua_modules"]
teal = ["bevy_mod_scripting_lua/teal"]
Expand All @@ -59,6 +60,7 @@ rhai_script_api = ["bevy_script_api/rhai"]

## rune
rune = ["bevy_mod_scripting_rune"]
rune_script_api = ["bevy_script_api/rune"]

[dependencies]
bevy = { workspace = true }
Expand All @@ -68,7 +70,6 @@ bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", v
bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.6.0", optional = true }
bevy_script_api = { path = "crates/bevy_script_api", version = "0.6.0", optional = true }


[workspace.dependencies]
bevy = { version = "=0.13.1", default-features = false }
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.6.0" }
Expand All @@ -91,6 +92,7 @@ members = [
"crates/languages/bevy_mod_scripting_rhai",
"crates/languages/bevy_mod_scripting_rhai_derive",
"crates/languages/bevy_mod_scripting_rune",
"crates/languages/bevy_mod_scripting_rune_derive",
"crates/bevy_mod_scripting_common",
]
resolver = "2"
Expand Down
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 clippy --all-targets --message-format=json
else
cargo clippy --workspace --all-targets --message-format=json --features="lua54 lua_script_api rhai rhai_script_api teal rune bevy/file_watcher bevy/multi-threaded"
cargo clippy --workspace --all-targets --message-format=json --features="lua54 lua_script_api rhai rhai_script_api teal rune rune_script_api bevy/file_watcher bevy/multi-threaded"
fi
2 changes: 1 addition & 1 deletion crates/bevy_event_priority/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
description = "Bevy plugin providing priority based event handling"
repository = "https://github.com/makspll/bevy_mod_scripting"
homepage = "https://github.com/makspll/bevy_mod_scripting"
keywords = ["bevy", "gamedev", "scripting", "lua"]
keywords = ["bevy", "gamedev", "scripting", "lua", "rhai", "rune"]
categories = ["game-development"]
readme = "readme.md"

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mod_scripting_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
description = "Traits and syn structures for language implementors"
repository = "https://github.com/makspll/bevy_mod_scripting"
homepage = "https://github.com/makspll/bevy_mod_scripting"
keywords = ["bevy", "gamedev", "scripting", "lua"]
keywords = ["bevy", "gamedev", "scripting", "lua", "rhai", "rune"]
categories = ["game-development"]
readme = "readme.md"

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mod_scripting_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
description = "Core traits and structures required for other parts of bevy_mod_scripting"
repository = "https://github.com/makspll/bevy_mod_scripting"
homepage = "https://github.com/makspll/bevy_mod_scripting"
keywords = ["bevy", "gamedev", "scripting", "lua"]
keywords = ["bevy", "gamedev", "scripting", "lua", "rhai", "rune"]
categories = ["game-development"]
readme = "readme.md"

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mod_scripting_core/src/hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Default for Recipients {
pub trait ScriptHost: Send + Sync + 'static + Default + Resource {
/// the type of the persistent script context, representing the execution context of the script
type ScriptContext: Send + Sync + 'static;
/// the type of events picked up by lua callbacks
/// the type of events picked up by language callbacks
type ScriptEvent: ScriptEvent;
/// the type of asset representing the script files for this host
type ScriptAsset: CodeAsset;
Expand Down
12 changes: 9 additions & 3 deletions crates/bevy_script_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ license = "MIT OR Apache-2.0"
description = "Bevy API for multiple script languages, part of bevy_mod_scripting."
repository = "https://github.com/makspll/bevy_mod_scripting"
homepage = "https://github.com/makspll/bevy_mod_scripting"
keywords = ["bevy", "gamedev", "scripting", "lua", "rhai"]
keywords = ["bevy", "gamedev", "scripting", "lua", "rhai", "rune"]
categories = ["game-development"]
readme = "readme.md"

[features]
lua = ["bevy_mod_scripting_lua", "bevy_mod_scripting_lua_derive"]
rhai = ["bevy_mod_scripting_rhai"]
rune = ["bevy_mod_scripting_rune"]

[dependencies]
bevy = { workspace = true, default-features = false, features = [
Expand All @@ -33,9 +34,14 @@ bevy_mod_scripting_core = { workspace = true }
parking_lot = "0.12.1"
paste = "1.0.7"
thiserror = "1.0.32"
smol_str = "0.2"
allocator-api2 = "0.2"
# lua
bevy_mod_scripting_lua = { path = "../languages/bevy_mod_scripting_lua", version = "0.6.0", optional = true }
bevy_mod_scripting_lua_derive = { path = "../languages/bevy_mod_scripting_lua_derive", version = "0.6.0", optional = true }
# rhai
bevy_mod_scripting_rhai = { path = "../languages/bevy_mod_scripting_rhai", version = "0.6.0", optional = true }
smol_str = "0.2"
allocator-api2 = "0.2"
bevy_mod_scripting_rhai_derive = { path = "../languages/bevy_mod_scripting_rhai_derive", version = "0.6.0", optional = true }
#rune
bevy_mod_scripting_rune = { path = "../languages/bevy_mod_scripting_rune", version = "0.6.0", optional = true }
bevy_mod_scripting_rune_derive = { path = "../languages/bevy_mod_scripting_rune_derive", version = "0.6.0", optional = true }
7 changes: 7 additions & 0 deletions crates/bevy_script_api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@
.into()
}
}

#[cfg(feature = "rune")]
impl From<ReflectionError> for Box<bevy_mod_scripting_rune::rune::runtime::VmError> {
fn from(e: ReflectionError) -> Self {

Check warning on line 41 in crates/bevy_script_api/src/error.rs

View workflow job for this annotation

GitHub Actions / Docs

unused variable: `e`

Check warning on line 41 in crates/bevy_script_api/src/error.rs

View workflow job for this annotation

GitHub Actions / Tests

unused variable: `e`
todo!()
}
}
5 changes: 5 additions & 0 deletions crates/bevy_script_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub mod error;
pub mod lua;
#[cfg(feature = "rhai")]
pub mod rhai;
#[cfg(feature = "rune")]
pub mod rune;

pub mod common;

Expand Down Expand Up @@ -36,6 +38,9 @@ pub mod prelude {
FromRhaiProxy, ReflectRhaiProxyable, RhaiProxyable, ToRhaiProxy,
};

#[cfg(feature = "rune")]
pub use crate::rune;

pub use crate::{common::bevy::GetWorld, ValueIndex};
}

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_script_api/src/rhai/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,15 @@ impl<T: RhaiVecElem> RhaiProxyable for Vec<T> {
) -> Result<(), Box<EvalAltResult>> {
if new_val.is::<Vec<Dynamic>>() {
let last_target_idx = self_.get_typed(|s: &Vec<T>| s.len())? - 1;
// there is also another case to consider, Vec has a lua representation available as well (table)
// there is also another case to consider, Vec has a rhai representation available as well (table)
// if we receive one of those, we should also apply it
for (idx, entry) in new_val.cast::<Vec<Dynamic>>().into_iter().enumerate() {
if idx > last_target_idx {
// here we don't need to do anything special just use LuaProxyable impl
// here we don't need to do anything special just use RhaiProxyable impl
T::apply_rhai(&mut self_.index(idx), entry)?;
} else {
// here we don't have anything to apply this to
// use FromLua impl
// use FromRhai impl
self_.get_mut_typed(|s: &mut Vec<T>| {
s[idx] = T::from_rhai_proxy(entry)?;
Ok::<_, Box<EvalAltResult>>(())
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion crates/languages/bevy_mod_scripting_lua/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
description = "Necessary functionality for Lua support with bevy_mod_scripting"
repository = "https://github.com/makspll/bevy_mod_scripting"
homepage = "https://github.com/makspll/bevy_mod_scripting"
keywords = ["bevy", "gamedev", "scripting", "rhai"]
keywords = ["bevy", "gamedev", "scripting", "lua"]
categories = ["game-development"]
readme = "readme.md"

Expand Down
2 changes: 1 addition & 1 deletion crates/languages/bevy_mod_scripting_lua_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
description = "Necessary functionality for Lua support with bevy_mod_scripting"
repository = "https://github.com/makspll/bevy_mod_scripting"
homepage = "https://github.com/makspll/bevy_mod_scripting"
keywords = ["bevy", "gamedev", "scripting", "rhai"]
keywords = ["bevy", "gamedev", "scripting", "lua"]
categories = ["game-development"]
readme = "readme.md"

Expand Down
2 changes: 1 addition & 1 deletion crates/languages/bevy_mod_scripting_rhai/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl CodeAsset for RhaiFile {
}

#[derive(Default)]
/// Asset loader for lua scripts
/// Asset loader for rhai scripts
pub struct RhaiLoader;

impl AssetLoader for RhaiLoader {
Expand Down
9 changes: 5 additions & 4 deletions crates/languages/bevy_mod_scripting_rhai/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ use bevy_mod_scripting_core::{prelude::*, systems::*, world::WorldPointerGuard};
use rhai::*;
use std::marker::PhantomData;

pub use rhai;

pub mod assets;
pub mod docs;
pub use rhai;

pub mod prelude {
pub use crate::{
assets::{RhaiFile, RhaiLoader},
docs::RhaiDocFragment,
RhaiContext, RhaiEvent, RhaiScriptHost,
};
pub use rhai;
pub use rhai::{Engine, FuncArgs};
pub use rhai::{self, Engine, FuncArgs};
}

#[derive(Resource)]
Expand Down Expand Up @@ -49,7 +50,7 @@ pub struct RhaiContext {

#[derive(Clone, Event)]
/// A Rhai Hook. The result of creating this event will be
/// a call to the lua script with the hook_name and the given arguments
/// a call to the rhai script with the hook_name and the given arguments
pub struct RhaiEvent<A: FuncArgs + Clone + 'static> {
pub hook_name: String,
pub args: A,
Expand Down
2 changes: 1 addition & 1 deletion crates/languages/bevy_mod_scripting_rhai_derive/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# bevy_mod_scripting_lua_derive
# bevy_mod_scripting_rhai_derive

This crate is a part of the ["bevy_mod_scripting" workspace](https://github.com/makspll/bevy_mod_scripting).
2 changes: 1 addition & 1 deletion crates/languages/bevy_mod_scripting_rhai_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use proc_macro::TokenStream;

#[proc_macro]
pub fn impl_lua_newtype(tokens: TokenStream) -> TokenStream {
pub fn impl_rhai_newtype(tokens: TokenStream) -> TokenStream {
// let newtype = parse_macro_input!(tokens as Newtype);

// implementor
Expand Down
6 changes: 4 additions & 2 deletions crates/languages/bevy_mod_scripting_rune/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ use rune::{
Context, Diagnostics, Source, Sources, Unit, Vm,
};

mod assets;
mod docs;
pub use rune;

pub mod assets;
pub mod docs;

pub mod prelude {
pub use crate::{
Expand Down
29 changes: 29 additions & 0 deletions crates/languages/bevy_mod_scripting_rune_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "bevy_mod_scripting_rune_derive"
version = "0.6.0"
authors = ["Maksymilian Mozolewski <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Necessary functionality for Rune support with bevy_mod_scripting"
repository = "https://github.com/makspll/bevy_mod_scripting"
homepage = "https://github.com/makspll/bevy_mod_scripting"
keywords = ["bevy", "gamedev", "scripting", "rune"]
categories = ["game-development"]
readme = "readme.md"

[lib]
name = "bevy_mod_scripting_rune_derive"
path = "src/lib.rs"
proc-macro = true

[dependencies]
bevy_mod_scripting_common = { path = "../../bevy_mod_scripting_common", version = "0.6.0" }
paste = "1.0.7"
syn = { version = "1.0.57", features = ["full", "fold", "extra-traits"] }
quote = "1.0.8"
proc-macro2 = "1.0"
convert_case = "0.5.0"
rustdoc-types = "0.11.0"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0.137"
indexmap = { version = "1.9.1", features = ["serde"] }
3 changes: 3 additions & 0 deletions crates/languages/bevy_mod_scripting_rune_derive/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# bevy_mod_scripting_rune_derive

This crate is a part of the ["bevy_mod_scripting" workspace](https://github.com/makspll/bevy_mod_scripting).
13 changes: 13 additions & 0 deletions crates/languages/bevy_mod_scripting_rune_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use proc_macro::TokenStream;

#[proc_macro]
pub fn impl_rune_newtype(tokens: TokenStream) -> TokenStream {
// let newtype = parse_macro_input!(tokens as Newtype);

// implementor
// .generate(newtype)
// .map_err(|e| e.to_compile_error())
// .unwrap_or_else(core::convert::identity)
// .into()
tokens
}
5 changes: 4 additions & 1 deletion src/documentation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
.add_plugins(ScriptingPlugin)
.add_plugins(AssetPlugin::default());

static INVALID_ARGUMENT_WARNING: &str = "Expected one of: 'lua','rhai' as arguments";
static INVALID_ARGUMENT_WARNING: &str = "Expected one of: 'lua','rhai','rune' as arguments";

let lang = args.get(1).expect(INVALID_ARGUMENT_WARNING);

Expand All @@ -27,6 +27,9 @@ fn main() {
"rhai" => {
println!("Rhai documentation generation is not supported yet");
}
"rune" => {
println!("Rune documentation generation is not supported yet");
}
_ => println!("{}", INVALID_ARGUMENT_WARNING),
}
}
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@
#[cfg(feature = "rune")]
pub mod rune {
pub use bevy_mod_scripting_rune::*;

#[cfg(feature = "rune_script_api")]
pub mod api {
pub use bevy_script_api::rune::*;

Check warning on line 33 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Docs

unused import: `bevy_script_api::rune::*`
}
}

#[cfg(any(feature = "lua_script_api", feature = "rhai_script_api"))]
#[cfg(any(
feature = "lua_script_api",
feature = "rhai_script_api",
feature = "rune_script_api"
))]
pub mod api {
pub use bevy_script_api::*;
}
Expand All @@ -44,8 +53,12 @@
pub use bevy_mod_scripting_rhai::prelude::*;

#[cfg(feature = "rune")]
pub use bevy_mod_scripting_rune::prelude::*;

Check warning on line 56 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Docs

ambiguous glob re-exports

Check warning on line 56 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Tests

ambiguous glob re-exports

#[cfg(any(feature = "lua_script_api", feature = "rhai_script_api"))]
#[cfg(any(
feature = "lua_script_api",
feature = "rhai_script_api",
feature = "rune_script_api"
))]
pub use bevy_script_api::prelude::*;
}
Loading