Skip to content

Commit f8456e6

Browse files
committed
LETS GOO
1 parent 66d24fc commit f8456e6

File tree

73 files changed

+997
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+997
-29
lines changed

crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl ScriptFunctionRegistryArc {
353353
}
354354
}
355355

356-
#[derive(Debug, PartialEq, Eq, Hash)]
356+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
357357
pub struct FunctionKey {
358358
pub name: Cow<'static, str>,
359359
pub namespace: Namespace,
@@ -504,6 +504,23 @@ impl ScriptFunctionRegistry {
504504
pub fn iter_all(&self) -> impl Iterator<Item = (&FunctionKey, &DynamicScriptFunction)> {
505505
self.functions.iter()
506506
}
507+
508+
/// Insert a function into the registry with the given key, this will not perform any overloading logic.
509+
/// Do not use unless you really need to.
510+
pub fn raw_insert(
511+
&mut self,
512+
namespace: Namespace,
513+
name: impl Into<Cow<'static, str>>,
514+
func: DynamicScriptFunction,
515+
) {
516+
self.functions.insert(
517+
FunctionKey {
518+
name: name.into(),
519+
namespace,
520+
},
521+
func,
522+
);
523+
}
507524
}
508525

509526
macro_rules! count {

crates/bevy_mod_scripting_core/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use context::{
1313
Context, ContextAssigner, ContextBuilder, ContextInitializer, ContextLoadingSettings,
1414
ContextPreHandlingInitializer, ScriptContexts,
1515
};
16+
use error::ScriptError;
1617
use event::ScriptCallbackEvent;
1718
use handler::{CallbackSettings, HandlerFn};
1819
use runtime::{initialize_runtime, Runtime, RuntimeContainer, RuntimeInitializer, RuntimeSettings};
@@ -213,7 +214,12 @@ fn once_per_app_init(app: &mut App) {
213214
fn register_script_plugin_systems<P: IntoScriptPluginParams>(app: &mut App) {
214215
app.add_systems(
215216
PostStartup,
216-
(initialize_runtime::<P>).in_set(ScriptingSystemSet::RuntimeInitialization),
217+
(initialize_runtime::<P>.pipe(|e: In<Result<(), ScriptError>>| {
218+
if let Err(e) = e.0 {
219+
error!("Error initializing runtime: {:?}", e);
220+
}
221+
}))
222+
.in_set(ScriptingSystemSet::RuntimeInitialization),
217223
);
218224

219225
configure_asset_systems_for_plugin::<P>(app);

crates/bevy_mod_scripting_core/src/runtime.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! "Runtime" here refers to the execution evironment of scripts. This might be the VM executing bytecode or the interpreter executing source code.
22
//! The important thing is that there is only one runtime which is used to execute all scripts of a particular type or `context`.
33
4-
use crate::IntoScriptPluginParams;
4+
use crate::{error::ScriptError, IntoScriptPluginParams};
55
use bevy::{
66
ecs::system::Resource,
77
prelude::{NonSendMut, Res},
@@ -10,7 +10,8 @@ use bevy::{
1010
pub trait Runtime: 'static {}
1111
impl<T: 'static> Runtime for T {}
1212

13-
pub type RuntimeInitializer<P> = fn(&mut <P as IntoScriptPluginParams>::R);
13+
pub type RuntimeInitializer<P> =
14+
fn(&mut <P as IntoScriptPluginParams>::R) -> Result<(), ScriptError>;
1415

1516
#[derive(Resource)]
1617
pub struct RuntimeSettings<P: IntoScriptPluginParams> {
@@ -42,8 +43,9 @@ pub struct RuntimeContainer<P: IntoScriptPluginParams> {
4243
pub fn initialize_runtime<P: IntoScriptPluginParams>(
4344
mut runtime: NonSendMut<RuntimeContainer<P>>,
4445
settings: Res<RuntimeSettings<P>>,
45-
) {
46+
) -> Result<(), ScriptError> {
4647
for initializer in settings.initializers.iter() {
47-
(initializer)(&mut runtime.runtime);
48+
(initializer)(&mut runtime.runtime)?;
4849
}
50+
Ok(())
4951
}

crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,6 @@ impl UserData for LuaStaticReflectReference {
277277

278278
let key: ScriptValue = key.into();
279279

280-
// if let ScriptValue::String(ref key) = key {
281-
// if let Some(func) = lookup_function(lua, key, type_id) {
282-
// return func?.into_lua(lua);
283-
// }
284-
// };
285280
let key = match key.as_string() {
286281
Ok(name) => match world.lookup_function([type_id], name) {
287282
Ok(func) => return Ok(LuaScriptValue(ScriptValue::Function(func))),

crates/languages/bevy_mod_scripting_rhai/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rhai = { workspace = true, features = ["sync"] }
2121
bevy_mod_scripting_core = { workspace = true, features = ["rhai_impls"] }
2222
bevy_mod_scripting_functions = { workspace = true, features = [
2323
], default-features = false }
24+
strum = { version = "0.26", features = ["derive"] }
2425

2526
[dev-dependencies]
2627
script_integration_test_harness = { workspace = true }

0 commit comments

Comments
 (0)