Skip to content

Commit 64fb363

Browse files
authored
Merge pull request #1008 from godot-rust/bugfix/decl-macro-generated
Test generation of proc-macro code via declarative macro
2 parents 9d5617d + 6c64b6a commit 64fb363

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

.github/other/public-docs-token.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
MTFBQUZNN0NBMHpNWHlZeVBFZUl1bl9kdm5NOUV3RkZlVll6RVhNeGpvaHFVR1pyd1BSWUxjQ3cyYzFlUnZmR2VRRDZBUjJWT0NpdTRRSWVuUgo=
1+
MTFBQUZNN0NBMGdXTnFGVGZ4SHA3UV9NMjlrUlljMm80cHUwYzNPbEM3b1V1WkhMTXZrT2R0aDRzTlF1cVZ6dkZBSTdSQkM3WEYzME5MQ0VuNAo=

godot-macros/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ proc-macro = true
2222
# Minimum versions compatible with -Zminimal-versions
2323
proc-macro2 = "1.0.80" # Literal::c_string() added in 1.0.80.
2424
quote = "1.0.29"
25-
26-
# Enabled by `docs`
25+
# Enabled by `docs`.
2726
markdown = { version = "=1.0.0-alpha.21", optional = true }
28-
venial = "0.6"
27+
# Requires bugfixes from 0.6.1.
28+
venial = "0.6.1"
2929

3030
[build-dependencies]
3131
godot-bindings = { path = "../godot-bindings", version = "=0.2.3" } # emit_godot_version_cfg

itest/rust/src/engine_tests/codegen_test.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,45 @@ impl CodegenTest2 {
128128
#[func(virtual)]
129129
fn with_virtual_many_unnamed(&self, _: i32, _: GString) {}
130130
}
131+
132+
// ----------------------------------------------------------------------------------------------------------------------------------------------
133+
// Generation of APIs via declarative macro.
134+
135+
macro_rules! make_class {
136+
($ClassName:ident, $BaseName:ident) => {
137+
#[derive(GodotClass)]
138+
#[class(no_init, base=$BaseName)]
139+
pub struct $ClassName {
140+
base: Base<godot::classes::$BaseName>,
141+
}
142+
};
143+
}
144+
145+
macro_rules! make_interface_impl {
146+
($Class:ty, $Trait:path) => {
147+
#[godot_api]
148+
#[allow(unused)]
149+
impl $Trait for $Class {
150+
fn init(base: Base<Self::Base>) -> Self {
151+
Self { base }
152+
}
153+
154+
fn process(&mut self, _: f64) {}
155+
}
156+
};
157+
}
158+
159+
macro_rules! make_user_api {
160+
($Class:ty, $method:ident, $Param:ty) => {
161+
#[godot_api]
162+
#[allow(unused)]
163+
impl $Class {
164+
#[func]
165+
fn $method(&self, _m: $Param) {}
166+
}
167+
};
168+
}
169+
170+
make_class!(CodegenTest3, Node3D);
171+
make_interface_impl!(CodegenTest3, INode3D);
172+
make_user_api!(CodegenTest3, take_param, i32);

0 commit comments

Comments
 (0)