Skip to content

Commit 811ef75

Browse files
committed
fix lifetime issue, allow refs
1 parent d40838b commit 811ef75

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

assets/scripts/bevy_api.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function on_event()
1515
print(script)
1616
print(world)
1717

18+
print(world:hello(entity))
1819
print(world:test_vec({entity, entity})[1])
1920

2021

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<T> Deref for Ref<'_, T> {
146146
}
147147

148148
impl<T: FromReflect> FromScript for Ref<'_, T> {
149-
type This<'w> = Ref<'w, T>;
149+
type This<'a> = Ref<'a, T>;
150150

151151
fn from_script(
152152
value: ScriptValue,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ macro_rules! impl_script_function {
3434
(@ $( $param:ident ),* : $(($callback:ident: $callbackty:ty))? -> O => $res:ty $(where $out:ident)?) => {
3535
#[allow(non_snake_case)]
3636
impl<
37+
'l,
3738
$( $param: FromScript, )*
3839
O,
3940
F
@@ -43,7 +44,7 @@ macro_rules! impl_script_function {
4344
where
4445
O: IntoScript,
4546
F: Fn( $( $callbackty, )? $($param ),* ) -> $res + Send + Sync + 'static,
46-
$( for<'a> $param::This<'a>: Into<$param>, )*
47+
$( $param::This<'l>: Into<$param>),*
4748
{
4849
fn into_dynamic_function(self) -> DynamicFunction<'static> {
4950
(move |world: WorldCallbackAccess, $( $param: ScriptValue ),* | {

crates/bevy_mod_scripting_functions/src/core.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use bevy::{
1010
};
1111
use bevy_mod_scripting_core::*;
1212
use bindings::{
13-
function::{from::Val, script_function::ScriptFunction},
13+
function::{
14+
from::{Ref, Val},
15+
script_function::ScriptFunction,
16+
},
1417
script_value::{FromScriptValue, IntoScriptValue, ScriptValue},
1518
ReflectReference, ReflectionPathExt, ScriptTypeRegistration, WorldAccessGuard,
1619
WorldCallbackAccess,
@@ -58,7 +61,7 @@ assert_is_script_function!(|a: Val<usize>| Ok(2));
5861

5962
fn register_world_functions(reg: &mut FunctionRegistry) -> Result<(), FunctionRegistrationError> {
6063
NamespaceBuilder::<WorldCallbackAccess>::new(reg)
61-
// .overwrite_script_function("hello", |a: Val<usize>| 2)
64+
.overwrite_script_function("hello", |b: Ref<Entity>| None::<usize>)
6265
.overwrite(
6366
"test_vec",
6467
|s: WorldCallbackAccess, entities: Vec<Entity>| entities,

0 commit comments

Comments
 (0)