Skip to content

Commit 4287594

Browse files
committed
Trick to cause compile error when missing #[godot_api] attribute
Idea by @chitoyuu
1 parent 522dda7 commit 4287594

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

godot-core/src/bind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::obj::GodotClass;
2525
/// Do not call any of these methods directly -- they are an interface to Godot. Functionality
2626
/// described here is available through other means (e.g. `init` via `Gd::new_default`).
2727
#[allow(unused_variables)]
28-
pub trait GodotExt
28+
pub trait GodotExt: crate::private::You_forgot_the_attribute__godot_api
2929
where
3030
Self: GodotClass,
3131
{

godot-core/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ pub use godot_ffi as sys;
2222

2323
#[doc(hidden)]
2424
pub mod private {
25+
// If someone forgets #[godot_api], this causes a compile error, rather than virtual functions not being called at runtime.
26+
#[allow(non_camel_case_types)]
27+
pub trait You_forgot_the_attribute__godot_api {}
28+
2529
pub use crate::builtin::func_callbacks;
2630
pub use crate::engine::gen::classes::class_macros;
2731
pub use crate::registry::{callbacks, ClassPlugin, ErasedRegisterFn, PluginComponent};

godot-macros/src/godot_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ fn transform_trait_impl(original_impl: Impl) -> Result<TokenStream, Error> {
282282
#original_impl
283283
#godot_init_impl
284284

285+
impl ::godot::private::You_forgot_the_attribute__godot_api for #class_name {}
286+
285287
impl ::godot::obj::cap::ImplementsGodotExt for #class_name {
286288
fn __virtual_call(name: &str) -> ::godot::sys::GDNativeExtensionClassCallVirtual {
287289
//println!("virtual_call: {}.{}", std::any::type_name::<Self>(), name);

0 commit comments

Comments
 (0)