Skip to content

Commit e659214

Browse files
committed
feat: refactor generated bindings to use new derive macro
1 parent 324e5e1 commit e659214

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

crates/bevy_api_gen/templates/footer.tera

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,52 @@
77

88
pub struct {{ "ScriptingPlugin" | prefix_cratename | convert_case(case="upper_camel")}};
99

10+
{% for item in items %}
11+
#[script_bindings(
12+
remote,
13+
name = "{{ item.ident | convert_case(case="snake") }}",
14+
)]
15+
impl {{item.import_path}} {
16+
{%- for function in item.functions -%}
17+
18+
fn {{ function.ident }} (
19+
{%- for arg in function.args -%}
20+
{%- if arg.proxy_ty is matching("Mut.*")-%}
21+
mut {% endif -%}
22+
{{- arg.ident | to_arg_pattern() -}}
23+
: {{- arg.proxy_ty -}},
24+
{%- endfor -%}
25+
) {
26+
let output: {{ function.output.proxy_ty }} =
27+
{%- if function.from_trait_path -%}
28+
{{- function_call_expression(type=item.import_path, trait=function.from_trait_path, function=function.ident) -}}
29+
{%- else -%}
30+
{{- function_call_expression(type=item.import_path, function=function.ident) -}}
31+
{%- endif -%}
32+
(
33+
{%- for arg in function.args -%}
34+
{%- if arg.proxy_ty is matching("Ref.*")-%}
35+
&{% endif -%}
36+
{%- if arg.proxy_ty is matching ("Mut.*")-%}
37+
&mut {% endif -%}
38+
{{- arg.ident | to_arg_pattern() -}}
39+
{%- if arg.proxy_ty is matching("Val.*")-%}
40+
.into_inner()
41+
{%- endif -%},
42+
{%- endfor -%}
43+
).into();
44+
output
45+
}
46+
{%- endfor -%};
47+
}
48+
{% endfor %}
49+
1050
impl ::bevy::app::Plugin for {{ "ScriptingPlugin" | prefix_cratename | convert_case(case="upper_camel")}} {
1151
fn build(&self, app: &mut ::bevy::prelude::App) {
1252
let mut world = app.world_mut();
1353

1454
{% for item in items %}
15-
NamespaceBuilder::<::{{ item.import_path }}>::new(world)
16-
{%- for function in item.functions -%}
17-
.register("{{ function.ident }}", |
18-
{%- for arg in function.args -%}
19-
{%- if arg.proxy_ty is matching("Mut.*")-%}
20-
mut {% endif -%}
21-
{{- arg.ident | to_arg_pattern() -}}
22-
: {{- arg.proxy_ty -}},
23-
{%- endfor -%}
24-
| {
25-
let output: {{ function.output.proxy_ty }} =
26-
{%- if function.from_trait_path -%}
27-
{{- function_call_expression(type=item.import_path, trait=function.from_trait_path, function=function.ident) -}}
28-
{%- else -%}
29-
{{- function_call_expression(type=item.import_path, function=function.ident) -}}
30-
{%- endif -%}
31-
(
32-
{%- for arg in function.args -%}
33-
{%- if arg.proxy_ty is matching("Ref.*")-%}
34-
&{% endif -%}
35-
{%- if arg.proxy_ty is matching ("Mut.*")-%}
36-
&mut {% endif -%}
37-
{{- arg.ident | to_arg_pattern() -}}
38-
{%- if arg.proxy_ty is matching("Val.*")-%}
39-
.into_inner()
40-
{%- endif -%},
41-
{%- endfor -%}
42-
).into();
43-
output
44-
})
45-
{%- endfor -%};
55+
register_{{ item.ident | convert_case(case="snake") }}(&mut world);
4656
{% endfor %}
4757
}
4858
}

crates/bevy_api_gen/templates/header.tera

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use bevy_mod_scripting_core::{
88
function::{from::{Ref, Mut, Val}, namespace::{NamespaceBuilder}}
99
}
1010
};
11+
12+
use bevy_mod_scripting_derive::script_bindings;
13+
1114
{% if args.self_is_bms_lua %}
1215
use crate::*;
1316
{% else %}

0 commit comments

Comments
 (0)