Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename a few remaining occurrences of #[export] #935

Merged
merged 2 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/full-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ jobs:
testflags: '-- --skip ui_tests'
- os: { id: ubuntu-latest, name: linux }
rust: { toolchain: 'stable', postfix: ' (minimal-deps)', special: 'minimal-deps' }
testflags: '-- --skip ui_tests'
runs-on: ${{ matrix.os.id }}
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl HelloWorld {
HelloWorld
}

#[export]
fn _ready(&self, _owner: &Node) {
#[method]
fn _ready(&self, #[base] _node: &Node) {
godot_print!("Hello, world.");
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/property-export/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ impl PropertyExport {
Self::default()
}

#[export]
fn _ready(&self, _base: &Node) {
#[method]
fn _ready(&self) {
godot_print!("------------------------------------------------------------------");
godot_print!("Print from Rust (note the unordered map/set):");
godot_print!(" Vec (name):");
Expand Down
4 changes: 2 additions & 2 deletions gdnative/tests/ui/derive_fail_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ impl Foo {
Foo {}
}

#[export]
fn draw(&self, _owner: &Node) {}
#[method]
fn draw(&self) {}
}

fn main() {}
11 changes: 8 additions & 3 deletions gdnative/tests/ui/derive_fail_methods.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
error: cannot find attribute `export` in this scope
error: cannot find attribute `method` in this scope
--> $DIR/derive_fail_methods.rs:12:7
|
12 | #[export]
| ^^^^^^ help: a built-in attribute with a similar name exists: `expect`
12 | #[method]
| ^^^^^^ help: an attribute macro with a similar name exists: `methods`
|
::: $WORKSPACE/gdnative-derive/src/lib.rs
|
| pub fn methods(meta: TokenStream, input: TokenStream) -> TokenStream {
| -------------------------------------------------------------------- similarly named attribute macro `methods` defined here
27 changes: 10 additions & 17 deletions test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,22 @@ impl NotFoo {

#[methods]
impl Foo {
#[export]
fn answer(&self, _owner: &Reference) -> i64 {
#[method]
fn answer(&self, #[base] _base: &Reference) -> i64 {
self.0
}

#[export]
fn choose(
&self,
_owner: &Reference,
a: GodotString,
which: bool,
b: GodotString,
) -> GodotString {
#[method]
fn choose(&self, a: GodotString, which: bool, b: GodotString) -> GodotString {
if which {
a
} else {
b
}
}

#[export]
fn choose_variant(&self, _owner: &Reference, a: i32, what: Variant, b: f64) -> Variant {
#[method]
fn choose_variant(&self, a: i32, what: Variant, b: f64) -> Variant {
let what = what.try_to::<String>().expect("should be string");
match what.as_str() {
"int" => a.to_variant(),
Expand All @@ -148,13 +142,13 @@ impl Foo {

godot_itest! { test_rust_class_construction {
let foo = Foo::new_instance();
assert_eq!(Ok(42), foo.map(|foo, owner| { foo.answer(&owner) }));
assert_eq!(Ok(42), foo.map(|foo, base| { foo.answer(&base) }));

let base = foo.into_base();
assert_eq!(Some(42), unsafe { base.call("answer", &[]).to() });

let foo = Instance::<Foo, _>::try_from_base(base).expect("should be able to downcast");
assert_eq!(Ok(42), foo.map(|foo, owner| { foo.answer(&owner) }));
assert_eq!(Ok(42), foo.map(|foo, base| { foo.answer(&base) }));

let base = foo.into_base();
assert!(Instance::<NotFoo, _>::try_from_base(base).is_err());
Expand All @@ -172,11 +166,10 @@ impl OptionalArgs {

#[methods]
impl OptionalArgs {
#[export]
#[method]
#[allow(clippy::many_single_char_names)]
fn opt_sum(
&self,
_owner: &Reference,
&self, //
a: i64,
b: i64,
#[opt] c: i64,
Expand Down
4 changes: 2 additions & 2 deletions test/src/test_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl AsyncExecutorDriver {

#[methods]
impl AsyncExecutorDriver {
#[export]
fn _process(&self, _owner: &Node, _delta: f64) {
#[method]
fn _process(&self, _delta: f64) {
EXECUTOR.with(|e| e.pool.borrow_mut().run_until_stalled());
}
}
Expand Down
14 changes: 7 additions & 7 deletions test/src/test_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl MinimalDerive {
Self(54)
}

#[export]
#[export] // deliberately use old attribute
fn answer(&self, _owner: &Reference) -> i64 {
self.0
}
Expand All @@ -208,22 +208,22 @@ struct EmplacementOnly(i64);

#[methods]
impl EmplacementOnly {
#[export]
fn answer(&self, _owner: &Reference) -> i64 {
#[method]
fn answer(&self, #[base] _base: &Reference) -> i64 {
self.0
}
}

crate::godot_itest! { test_derive_nativeclass_without_constructor {
let foo = Instance::emplace(EmplacementOnly(54));
assert_eq!(Ok(54), foo.map(|foo, owner| { foo.answer(&owner) }));
assert_eq!(Ok(54), foo.map(|foo, base| { foo.answer(&base) }));

let base = foo.into_base();
assert_eq!(Some(54), unsafe { base.call("answer", &[]).to::<i64>() });

let foo = Instance::<EmplacementOnly, _>::try_from_base(base)
.expect("should be able to downcast");
assert_eq!(Ok(54), foo.map(|foo, owner| { foo.answer(&owner) }));
assert_eq!(Ok(54), foo.map(|foo, base| { foo.answer(&base) }));
}}

// ----------------------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -237,8 +237,8 @@ impl WithoutInherit {
Self(54)
}

#[export]
fn answer(&self, _owner: &Reference) -> i64 {
#[method]
fn answer(&self) -> i64 {
self.0
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/src/test_free_ub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ struct Bar(i64, Arc<AtomicUsize>);

#[methods]
impl Bar {
#[export]
fn free_is_not_ub(&mut self, owner: &Node) -> bool {
#[method]
fn free_is_not_ub(&mut self, #[base] owner: &Node) -> bool {
unsafe {
owner.assume_unique().free();
}
assert_eq!(42, self.0, "self should not point to garbage");
true
}

#[export]
fn set_script_is_not_ub(&mut self, owner: &Node) -> bool {
#[method]
fn set_script_is_not_ub(&mut self, #[base] owner: &Node) -> bool {
owner.set_script(Null::null());
assert_eq!(42, self.0, "self should not point to garbage");
true
Expand Down
8 changes: 4 additions & 4 deletions test/src/test_map_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct VecBuilder {

#[methods]
impl VecBuilder {
#[export]
fn append(mut self, _owner: TRef<Reference>, mut numbers: Vec<i32>) -> Instance<Self> {
#[method]
fn append(mut self, mut numbers: Vec<i32>) -> Instance<Self> {
self.v.append(&mut numbers);
Instance::emplace(Self { v: self.v }).into_shared()
}
Expand All @@ -35,15 +35,15 @@ crate::godot_itest! { test_map_owned {
let v1 = unsafe { v1.assume_safe() };

let v2 = v1
.map_owned(|s, owner| s.append(owner, vec![1, 2, 3]))
.map_owned(|s, _base| s.append(vec![1, 2, 3]))
.unwrap();
let v2 = unsafe { v2.assume_safe() };
assert!(v1
.map_owned(|_, _| panic!("should never be called"))
.is_err());

let v3 = v2
.map_owned(|s, owner| s.append(owner, vec![4, 5, 6]))
.map_owned(|s, _base| s.append(vec![4, 5, 6]))
.unwrap();
let v3 = unsafe { v3.assume_safe() };
assert!(v2
Expand Down
9 changes: 5 additions & 4 deletions test/src/test_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ impl StaticallyNamed for RegisterProperty {

#[methods]
impl RegisterProperty {
#[export]
fn set_value(&mut self, _owner: TRef<Reference>, value: i64) {
// Note: the _base parameter is necessary, because registration API with_setter/with_getter matches that signature
#[method]
fn set_value(&mut self, #[base] _base: TRef<Reference>, value: i64) {
self.value = value;
}

#[export]
fn get_value(&self, _owner: TRef<Reference>) -> i64 {
#[method]
fn get_value(&self, #[base] _base: TRef<Reference>) -> i64 {
self.value
}
}
Expand Down
16 changes: 8 additions & 8 deletions test/src/test_variant_call_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ impl StaticallyNamed for VariantCallArgs {

#[methods]
impl VariantCallArgs {
#[export]
fn zero(&mut self, _owner: &Reference) -> i32 {
#[method]
fn zero(&mut self) -> i32 {
42
}

#[export]
fn one(&mut self, _owner: &Reference, a: i32) -> i32 {
#[method]
fn one(&mut self, a: i32) -> i32 {
a * 42
}

#[export]
fn two(&mut self, _owner: &Reference, a: i32, b: i32) -> i32 {
#[method]
fn two(&mut self, a: i32, b: i32) -> i32 {
a * 42 + b
}

#[export]
fn three(&mut self, _owner: &Reference, a: i32, b: i32, c: i32) -> i32 {
#[method]
fn three(&mut self, a: i32, b: i32, c: i32) -> i32 {
a * 42 + b * c
}
}
Expand Down