Skip to content

Commit 6c339ce

Browse files
committed
refactor a bit
1 parent c805a2b commit 6c339ce

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

assets/scripts/bevy_api.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ function on_event()
3333
print("\nvec")
3434
-- print(table_to_string(comp.vec_of_usize))
3535
comp.vec_of_usize = {42,69,72}
36+
comp.vec_of_usize[1] = 612312312
37+
print(table_to_string(comp.vec_of_usize))
3638
-- comp.vec_of_usize[1] = 0
3739
-- print(comp.vec_of_usize[2])
3840
-- print(table_to_string(comp.vec_of_usize))

crates/bevy_mod_scripting_core/src/bindings/script_val.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ pub enum ScriptValue {
4242
World,
4343
}
4444

45-
// impl Into<ScriptValue> for ScriptResult<>
45+
impl From<()> for ScriptValue {
46+
fn from(_: ()) -> Self {
47+
ScriptValue::Unit
48+
}
49+
}
4650

4751
impl From<bool> for ScriptValue {
4852
fn from(value: bool) -> Self {

crates/bevy_mod_scripting_functions/src/core.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use bindings::{
1212
ReflectReference, ReflectionPathExt, ScriptTypeRegistration, WorldAccessGuard,
1313
WorldCallbackAccess,
1414
};
15+
use error::InteropError;
1516
use reflection_extensions::TypeIdExtensions;
1617

1718
use crate::namespaced_register::NamespaceBuilder;
@@ -101,7 +102,7 @@ fn register_world_functions(reg: &mut FunctionRegistry) -> Result<(), FunctionRe
101102
let path: ParsedPath = key.try_into().unwrap();
102103

103104
self_.index_path(path);
104-
self_
105+
let r: ScriptValue = self_
105106
.with_reflect_mut(world.clone(), |r| {
106107
let target_type_id = r
107108
.get_represented_type_info()
@@ -112,14 +113,13 @@ fn register_world_functions(reg: &mut FunctionRegistry) -> Result<(), FunctionRe
112113
world.clone(),
113114
target_type_id,
114115
)
115-
.transpose()
116-
.unwrap()
117-
.unwrap();
116+
.ok_or_else(|| InteropError::impossible_conversion(target_type_id))??;
118117

119118
r.try_apply(other.as_partial_reflect()).unwrap();
120-
ScriptValue::Unit
119+
Ok::<_, InteropError>(())
121120
})
122-
.unwrap();
121+
.into();
122+
return r;
123123
}
124124
ScriptValue::Unit
125125
},
@@ -134,9 +134,9 @@ fn register_world_functions(reg: &mut FunctionRegistry) -> Result<(), FunctionRe
134134
let world = world.read().expect("stale world");
135135
let mut path: ParsedPath = key.try_into().unwrap();
136136
path.convert_to_0_indexed();
137-
138137
self_.index_path(path);
139-
self_
138+
139+
let r: ScriptValue = self_
140140
.with_reflect_mut(world.clone(), |r| {
141141
let target_type_id = r
142142
.get_represented_type_info()
@@ -147,14 +147,13 @@ fn register_world_functions(reg: &mut FunctionRegistry) -> Result<(), FunctionRe
147147
world.clone(),
148148
target_type_id,
149149
)
150-
.transpose()
151-
.unwrap()
152-
.unwrap();
150+
.ok_or_else(|| InteropError::impossible_conversion(target_type_id))??;
153151

154152
r.try_apply(other.as_partial_reflect()).unwrap();
155-
ScriptValue::Unit
153+
Ok::<_, InteropError>(())
156154
})
157-
.unwrap();
155+
.into();
156+
return r;
158157
}
159158
ScriptValue::Unit
160159
},

0 commit comments

Comments
 (0)