Skip to content

Commit 6110b50

Browse files
committed
modify templates
1 parent ec1b101 commit 6110b50

File tree

3 files changed

+29
-44
lines changed

3 files changed

+29
-44
lines changed

crates/bevy_api_gen/templates/crate.tera

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,5 @@
22
{% filter prettyplease -%}
33
{% include "header.tera" %}
44

5-
{% for item in items %}
6-
{% include "item.tera" %}
7-
{% endfor %}
8-
95
{% include "footer.tera" %}
106
{%- endfilter -%}

crates/bevy_api_gen/templates/footer.tera

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,38 @@
44
{% set bms_lua_path="bevy_mod_scripting::lua"%}
55
{% endif %}
66

7-
#[derive(Default)]
8-
pub(crate) struct Globals;
9-
10-
impl {{bms_lua_path}}::tealr::mlu::ExportInstances for Globals {
11-
fn add_instances<'lua, T: {{bms_lua_path}}::tealr::mlu::InstanceCollector<'lua>>(
12-
self,
13-
instances: &mut T,
14-
) -> {{bms_lua_path}}::tealr::mlu::mlua::Result<()> {
15-
{% for item in items %}
16-
{% if item.has_static_methods %}
17-
instances.add_instance("{{ item.ident }}",
18-
{{bms_lua_path}}::tealr::mlu::UserDataProxy::<{{item.ident | prefix_lua}}>::new)?;
19-
{% endif %}
20-
{% endfor %}
21-
Ok(())
22-
}
23-
}
24-
25-
26-
fn {{ "ContextInitializer" | prefix_cratename | convert_case(case="snake") }} (_: &bevy_mod_scripting_core::script::ScriptId, ctx: &mut {{bms_lua_path}}::prelude::Lua) -> Result<(), bevy_mod_scripting_core::error::ScriptError> {
27-
{{bms_lua_path}}::tealr::mlu::set_global_env(Globals, ctx)?;
28-
Ok(())
29-
}
307

318
pub struct {{ "ScriptingPlugin" | prefix_cratename | convert_case(case="upper_camel")}};
329

3310
impl bevy::app::Plugin for {{ "ScriptingPlugin" | prefix_cratename | convert_case(case="upper_camel")}} {
3411
fn build(&self, app: &mut bevy::prelude::App) {
12+
let mut world = app.world_mut();
13+
3514
{% for item in items %}
36-
app.register_lua_proxy::<{{ item.import_path }}>();
15+
NamespaceBuilder::<{{ item.ident }}>::new(world)
16+
{%- for function in item.functions -%}
17+
.overwrite_script_function("{{ function.ident }}", |
18+
{%- for arg in function.args -%}
19+
{%- if arg.ident != "self" -%}
20+
{{- arg.ident -}}
21+
{%- else -%}
22+
_{{- arg.ident -}}
23+
{%- endif -%}
24+
: {{- arg.proxy_ty -}},
25+
{%- endfor -%}
26+
| {
27+
let output: {{ function.output.proxy_ty }} = {{ item.ident }}::{{ function.ident }}(
28+
{%- for arg in function.args -%}
29+
{%- if arg.ident != "self" -%}
30+
{{- arg.ident -}}
31+
{%- else -%}
32+
_{{- arg.ident -}}
33+
{%- endif -%}
34+
{%- endfor -%}
35+
).into();
36+
output
37+
})
38+
{%- endfor -%};
3739
{% endfor %}
38-
app.add_context_initializer::<()>({{ "ContextInitializer" | prefix_cratename | convert_case(case="snake") }});
39-
app.add_documentation_fragment(
40-
{{bms_lua_path}}::docs::LuaDocumentationFragment::new("{{ "A P I" | prefix_cratename | convert_case(case="upper_camel") }}", |tw| {
41-
tw
42-
.document_global_instance::<Globals>().expect("Something went wrong documenting globals")
43-
{% for item in items %}
44-
.process_type::<{{ item.ident | prefix_lua }}>()
45-
{% if item.has_static_methods %}
46-
.process_type::<{{bms_lua_path}}::tealr::mlu::UserDataProxy<{{ item.ident | prefix_lua }}>>()
47-
{% endif %}
48-
{% endfor %}
49-
}
50-
)
51-
);
5240
}
5341
}

crates/bevy_api_gen/templates/header.tera

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ use super::{{crate}}::*;
1010

1111

1212
use bevy_mod_scripting_core::{AddContextInitializer, StoreDocumentation, bindings::ReflectReference};
13+
use bevy_mod_scripting_functions::RegisterScriptFunction;
1314

1415
{% if args.self_is_bms_lua %}
15-
use crate::{bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,LuaIdentityProxy},type_data::RegisterLua, tealr::mlu::mlua::IntoLua};
16+
use crate::*;
1617
{% else %}
17-
use bevy_mod_scripting::{lua::bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,LuaIdentityProxy}, type_data::RegisterLua, tealr::mlu::mlua::IntoLua};
18+
use bevy_mod_scripting_lua::*;
1819
{% endif %}

0 commit comments

Comments
 (0)