Skip to content
Open
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
21 changes: 19 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ lua_language_server_files = [
"ladfile_builder/lua_language_server_files",
]


# bindings
core_functions = ["bevy_mod_scripting_functions/core_functions"]

Expand Down Expand Up @@ -106,6 +107,10 @@ mlua_async = ["bevy_mod_scripting_lua?/mlua_async"]
## rhai
rhai = ["bevy_mod_scripting_rhai", "bevy_mod_scripting_functions/rhai_bindings"]


## wasmtime
wasmtime = ["bevy_mod_scripting_wasmtime"]

## rune
# rune = ["bevy_mod_scripting_rune"]

Expand All @@ -118,6 +123,7 @@ bevy_app = { workspace = true }
bevy_mod_scripting_core = { workspace = true }
bevy_mod_scripting_lua = { workspace = true, optional = true }
bevy_mod_scripting_rhai = { workspace = true, optional = true }
bevy_mod_scripting_wasmtime = { workspace = true, optional = true}
bevy_mod_scripting_functions = { workspace = true }
bevy_mod_scripting_derive = { workspace = true }
bevy_mod_scripting_asset = { workspace = true }
Expand All @@ -140,12 +146,16 @@ ladfile = { path = "crates/ladfile", version = "0.19.0" }
ladfile_builder = { path = "crates/ladfile_builder", version = "0.19.0" }
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.19.0", default-features = false }
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.19.0", default-features = false }
bevy_mod_scripting_wasmtime = { path = "crates/languages/bevy_mod_scripting_wasmtime", version = "0.19.0", default-features = false }

bevy_mod_scripting_asset = { path = "crates/bevy_mod_scripting_asset", version = "0.19.0", default-features = false }
bevy_mod_scripting_bindings = { path = "crates/bevy_mod_scripting_bindings", version = "0.19.0", default-features = false }
bevy_mod_scripting_bindings_domain = { path = "crates/bevy_mod_scripting_bindings_domain", version = "0.19.0", default-features = false }
bevy_mod_scripting_display = { path = "crates/bevy_mod_scripting_display", version = "0.19.0", default-features = false }
bevy_mod_scripting_script = { path = "crates/bevy_mod_scripting_script", version = "0.19.0", default-features = false }
lua_language_server_lad_backend = { path = "crates/lad_backends/lua_language_server_lad_backend", version = "0.19.0", default-features = false }
lad_wit_backend = { path = "crates/lad_backends/lad_wit_backend" , version = "0.19.0" }

bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.19.0" }
bevy_mod_scripting_world = { path = "crates/bevy_mod_scripting_world", version = "0.19.0", default-features = true}
# bevy
Expand Down Expand Up @@ -293,10 +303,10 @@ members = [
"crates/bevy_mod_scripting_script",
"crates/bevy_mod_scripting_bindings_domain",
"crates/bindings/*",
"crates/testing_crates/bevy_mod_scripting_test_scenario_syntax", "crates/bevy_mod_scripting_world",
"crates/testing_crates/bevy_mod_scripting_test_scenario_syntax", "crates/bevy_mod_scripting_world", "crates/languages/bevy_mod_scripting_wasmtime", "crates/lad_backends/lad_wit_backend",
]
resolver = "2"
exclude = ["codegen", "crates/macro_tests", "xtask"]
exclude = ["codegen", "crates/macro_tests", "xtask", "guest_crate/"]

[profile.dev]
debug = 1
Expand Down Expand Up @@ -340,6 +350,13 @@ required-features = ["lua_language_server_files"]
name = "runscript"
path = "examples/run_script.rs"


[[example]]
name = "run_wasm"
path = "examples/run_wasm.rs"
required-features = ["wasmtime"]


[[example]]
name = "script_loading"
path = "examples/script_loading.rs"
Expand Down
Binary file added assets/scripts/bms_wasm_guest.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions crates/bevy_mod_scripting_asset/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub enum Language {
Lua,
/// The Rune scripting language
Rune,
/// Any wasmtime compiled language
Wasmtime,
/// An external scripting language
External {
/// The identifier of the language
Expand Down Expand Up @@ -52,6 +54,7 @@ impl From<&Language> for Cow<'static, str> {
Language::Lua => Cow::Borrowed("Lua"),
Language::Rune => Cow::Borrowed("Rune"),
Language::External { name, .. } => name.clone(),
Language::Wasmtime => Cow::Borrowed("Wasmtime"),
Language::Unknown => Cow::Borrowed("Unknown"),
}
}
Expand Down
29 changes: 23 additions & 6 deletions crates/bevy_mod_scripting_bindings/src/docgen/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::function::arg_meta::ArgMeta;
use crate::function::namespace::Namespace;
use bevy_ecs::world::World;
use bevy_mod_scripting_derive::DebugWithTypeInfo;
use bevy_mod_scripting_display::{DisplayWithTypeInfo, WithTypeInfo};
use bevy_mod_scripting_world::WorldGuard;
Expand Down Expand Up @@ -44,6 +45,17 @@ impl Default for FunctionInfo {

#[profiling::all_functions]
impl FunctionInfo {
/// returns true if the function is defined with a first non-contextual argument matching its namespace
pub fn is_method(&self) -> bool {
self.arg_info
.iter()
.find(|a| a.is_passed)
.is_some_and(|a| match self.namespace {
Namespace::Global => false,
Namespace::OnType(type_id) => type_id == a.through_type_id(),
})
}

/// Create a new function info with default values.
pub fn new() -> Self {
Self {
Expand Down Expand Up @@ -128,6 +140,8 @@ pub struct FunctionArgInfo {
/// The type information of the argument.
#[reflect(ignore)]
pub type_info: Option<ThroughTypeInfo>,
/// True if this is a passed argument and false if it's purely injected and not interacted with from scripts
pub is_passed: bool,
}

impl DisplayWithTypeInfo for FunctionArgInfo {
Expand All @@ -148,12 +162,6 @@ impl DisplayWithTypeInfo for FunctionArgInfo {

#[profiling::all_functions]
impl FunctionArgInfo {
/// Create a new function argument info with a name.
pub fn with_name(mut self, name: Cow<'static, str>) -> Self {
self.name = Some(name);
self
}

/// Create a new function argument info for a specific type.
pub fn for_type<T: TypedThrough + 'static>(
name: Option<impl Into<Cow<'static, str>>>,
Expand All @@ -164,6 +172,15 @@ impl FunctionArgInfo {
arg_index,
type_id: TypeId::of::<T>(),
type_info: Some(T::through_type_info()),
is_passed: T::is_passed(),
}
}

/// Returns the type id of the first typed argument (i.e. for `R<T>` it would be the type id of `T`, ignoring any context arguments)
pub fn through_type_id(&self) -> TypeId {
match &self.type_info {
Some(ThroughTypeInfo::UntypedWrapper { through_type, .. }) => through_type.type_id(),
_ => self.type_id,
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion crates/bevy_mod_scripting_bindings/src/docgen/typed_through.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ pub fn as_reflect_primitive(type_info: &'static TypeInfo) -> Option<ReflectionPr
pub trait TypedThrough {
/// Get the [`ThroughTypeInfo`] for the type.
fn through_type_info() -> ThroughTypeInfo;
/// Returns true if this argument is a "proper" passed argument, and false if it's purely injected
fn is_passed() -> bool {
true
}
}

impl<T1: TypedThrough, T2: TypedThrough> TypedThrough for Union<T1, T2> {
Expand Down Expand Up @@ -313,7 +317,6 @@ macro_rules! impl_through_typed {
}

impl_through_typed!(
FunctionCallContext => FunctionCallContext,
ReflectReference => ReflectReference,
DynamicScriptFunctionMut => DynamicFunctionMut,
DynamicScriptFunction => DynamicFunction,
Expand All @@ -340,6 +343,16 @@ impl_through_typed!(
&'static str => Str
);

impl TypedThrough for FunctionCallContext {
fn through_type_info() -> ThroughTypeInfo {
ThroughTypeInfo::Primitive(ReflectionPrimitiveKind::FunctionCallContext)
}

fn is_passed() -> bool {
false
}
}

macro_rules! impl_through_typed_tuple {
($($ty:ident),*) => {
impl<$($ty: TypedThrough),*> TypedThrough for ($($ty,)*) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub struct LocationContext {
}

impl FunctionCallContext {
/// Create a new FunctionCallContext with the given 1-indexing conversion preference
/// Create a new FunctionCallContext
pub const fn new(language: Language) -> Self {
Self {
language,
Expand Down
Loading
Loading