Skip to content

Commit 3af3d82

Browse files
committed
Rename #[class(hide)] -> #[class(hidden)]; add utility to require minimum API version
1 parent e1011f3 commit 3af3d82

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

godot-macros/src/class/derive_godot_class.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::class::{
1313
make_property_impl, make_virtual_callback, BeforeKind, Field, FieldExport, FieldVar, Fields,
1414
SignatureInfo,
1515
};
16-
use crate::util::{bail, ident, path_ends_with_complex, KvParser};
16+
use crate::util::{bail, ident, path_ends_with_complex, require_api_version, KvParser};
1717
use crate::{util, ParseResult};
1818

1919
pub fn derive_godot_class(decl: Declaration) -> ParseResult<TokenStream> {
@@ -307,12 +307,7 @@ fn parse_struct_attributes(class: &Struct) -> ParseResult<ClassAttributes> {
307307

308308
// #[class(editor_plugin)]
309309
if let Some(attr_key) = parser.handle_alone_with_span("editor_plugin")? {
310-
if cfg!(before_api = "4.1") {
311-
return bail!(
312-
attr_key,
313-
"#[class(editor_plugin)] is not supported in Godot 4.0"
314-
);
315-
}
310+
require_api_version!("4.1", &attr_key, "#[class(editor_plugin)]")?;
316311

317312
is_editor_plugin = true;
318313

@@ -331,8 +326,9 @@ fn parse_struct_attributes(class: &Struct) -> ParseResult<ClassAttributes> {
331326
}
332327
}
333328

334-
// #[class(hide)]
335-
if parser.handle_alone("hide")? {
329+
// #[class(hidden)]
330+
if let Some(span) = parser.handle_alone_with_span("hidden")? {
331+
require_api_version!("4.2", span, "#[class(hidden)]")?;
336332
is_hidden = true;
337333
}
338334

godot-macros/src/class/godot_api.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::class::{
1313
into_signature_info, make_method_registration, make_virtual_callback, BeforeKind,
1414
FuncDefinition, SignatureInfo,
1515
};
16-
use crate::util::{bail, KvParser};
16+
use crate::util::{bail, require_api_version, KvParser};
1717
use crate::{util, ParseResult};
1818

1919
pub fn attribute_godot_api(input_decl: venial::Declaration) -> ParseResult<TokenStream> {
@@ -513,7 +513,12 @@ where
513513
let rename = parser.handle_expr("rename")?.map(|ts| ts.to_string());
514514

515515
// #[func(virtual)]
516-
let is_virtual = parser.handle_alone("virtual")?;
516+
let is_virtual = if let Some(span) = parser.handle_alone_with_span("virtual")? {
517+
require_api_version!("4.3", span, "#[func(virtual)]")?;
518+
true
519+
} else {
520+
false
521+
};
517522

518523
// #[func(gd_self)]
519524
let has_gd_self = parser.handle_alone("gd_self")?;

godot-macros/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,12 @@ use crate::util::ident;
391391
///
392392
/// ## Class hiding
393393
///
394-
/// If you want to register a class with Godot, but not have it show up in the editor then you can use `#[class(hide)]`.
394+
/// If you want to register a class with Godot, but not have it show up in the editor then you can use `#[class(hidden)]`.
395395
///
396396
/// ```
397397
/// # use godot::prelude::*;
398398
/// #[derive(GodotClass)]
399-
/// #[class(base=Node, init, hide)]
399+
/// #[class(base=Node, init, hidden)]
400400
/// pub struct Foo {}
401401
/// ```
402402
///

godot-macros/src/util/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,20 @@ macro_rules! bail {
5858
}
5959
}
6060

61-
pub(crate) use bail;
61+
macro_rules! require_api_version {
62+
($min_version:literal, $span:expr, $attribute:literal) => {
63+
if !cfg!(since_api = $min_version) {
64+
bail!(
65+
$span,
66+
"{} requires at least Godot API version {}",
67+
$attribute,
68+
$min_version
69+
)
70+
} else {
71+
Ok(())
72+
}
73+
};
74+
}
6275

6376
pub fn error_fn<T>(msg: impl AsRef<str>, tokens: T) -> Error
6477
where
@@ -73,7 +86,9 @@ macro_rules! error {
7386
}
7487
}
7588

89+
pub(crate) use bail;
7690
pub(crate) use error;
91+
pub(crate) use require_api_version;
7792

7893
pub fn reduce_to_signature(function: &Function) -> Function {
7994
let mut reduced = function.clone();

0 commit comments

Comments
 (0)