Skip to content

Commit b844a82

Browse files
committed
Strip module prefixes
1 parent 4394873 commit b844a82

File tree

6 files changed

+68
-68
lines changed

6 files changed

+68
-68
lines changed

src/faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ As a work-around, it is possible to use a ZST (zero-sized type):
108108
#[inherit(Object)]
109109
pub struct StaticUtil;
110110

111-
#[godot::methods]
111+
#[methods]
112112
impl StaticUtil {
113113
#[export]
114114
fn compute_something(&self, _owner: &Object, input: i32) -> i32 {
@@ -140,7 +140,7 @@ How can I access the Rust type given the Variant?
140140
This conversion can be accomplished by casting the `Variant` to a `Ref`, and then to an `Instance` or `RefInstance`, and mapping over it to access the Rust data type:
141141

142142
```rust
143-
#[godot::methods]
143+
#[methods]
144144
impl AnotherNativeScript {
145145

146146
#[export]

src/gdnative-overview/wrappers.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The generic smart pointer `gdnative::Ref<T, Access>` allows you to store `Object
1313
For example, storing a reference to a Godot `Node2D` instance in a struct would look as follows:
1414
```rust
1515
struct GodotNode {
16-
node_ref: gd::Ref<gd::api::Node2D>,
16+
node_ref: Ref<Node2D>,
1717
}
1818
```
1919

@@ -28,14 +28,14 @@ While `Ref` is a persistent pointer to retain references to Godot objects for an
2828
The following example demonstrates `TRef`. A node is stored inside a Rust struct, and its position is modified through `set_position()`. This approach could be used in an ECS (Entity-Component-System) architecture, where `GodotNode` is a component, updated by a system.
2929
```rust
3030
struct GodotNode {
31-
node_ref: gd::Ref<gd::api::Node2D>,
31+
node_ref: Ref<Node2D>,
3232
}
3333

3434
fn update_position(node: &GodotNode) {
35-
let pos = gd::core_types::Vector2::new(20, 30);
35+
let pos = Vector2::new(20, 30);
3636

3737
// fetch temporary reference to the node
38-
let node: gd::TRef<gd::api::Node2D> = unsafe { node.node_ref.assume_safe() };
38+
let node: TRef<Node2D> = unsafe { node.node_ref.assume_safe() };
3939

4040
// call into the Godot engine
4141
// this implicitly invokes deref(), turning TRef<Node2D> into &Node2D
@@ -69,16 +69,16 @@ When passing around your own Rust types, you will thus be working with `Instance
6969

7070
Let's use a straightforward example: a player with name and score. Exported methods and properties are omitted for simplicity; the full interfacing will be explained later in [Calling into GDScript from Rust](../rust-binding/calling-gdscript.md).
7171
```rust
72-
#[derive(gd::NativeClass)]
72+
#[derive(NativeClass)]
7373
// no #[inherit], thus inherits Reference by default
7474
pub struct Player {
7575
name: String,
7676
score: u32,
7777
}
7878

79-
#[gd::methods]
79+
#[methods]
8080
impl Player {
81-
fn new(_owner: &gd::Reference) -> Self {
81+
fn new(_owner: &Reference) -> Self {
8282
Self {
8383
name: "New player".to_string(),
8484
score: 0
@@ -104,14 +104,14 @@ instance.map_mut(|p: &mut Player, _base: TRef<Reference, Unique>| {
104104

105105
If you don't need a Godot-enabled default constructor, use the `#[no_constructor]` attribute and define your own Rust `new()` constructor.
106106
```rust
107-
#[derive(gd::NativeClass)]
107+
#[derive(NativeClass)]
108108
#[no_constructor]
109109
pub struct Player {
110110
name: String,
111111
score: u32,
112112
}
113113

114-
#[gd::methods]
114+
#[methods]
115115
impl Player {
116116
pub fn new(name: &str, score: u32) -> Self {
117117
Self { name: name.to_string(), score }

src/rust-binding/calling-gdscript.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ On the previous pages, we explained how to export a class, so it can be instanti
2020
Let's define a class `Enemy` which acts as a simple data bundle, i.e. no functionality. We inherit it from `Reference`, such that memory is managed automatically. In addition, we define `_to_string()` and delegate it to the derived `Debug` trait implementation, to make it printable from GDScript.
2121

2222
```rust
23-
#[derive(gd::NativeClass, Debug)]
23+
#[derive(NativeClass, Debug)]
2424
// no #[inherit], thus inherits Reference by default
2525
#[no_constructor]
2626
pub struct Enemy {
2727
#[property]
28-
pos: gd::core_types::Vector2,
28+
pos: Vector2,
2929

3030
#[property]
3131
health: f32,
@@ -34,35 +34,35 @@ pub struct Enemy {
3434
name: String,
3535
}
3636

37-
#[gd::methods]
37+
#[methods]
3838
impl Enemy {
3939
#[export]
40-
fn _to_string(&self, _owner: &gd::Reference) -> String {
40+
fn _to_string(&self, _owner: &Reference) -> String {
4141
format!("{:?}", self) // calls Debug::fmt()
4242
}
4343
}
4444
```
4545
Godot can only use classes that are registered, so let's do that:
4646
```rust
47-
fn init(handle: gd::nativescript::InitHandle) {
47+
fn init(handle: InitHandle) {
4848
// ...
4949
handle.add_class::<Enemy>();
5050
}
5151
```
5252
Now, it's not possible to directly return `Enemy` instances in exported methods, so this won't work:
5353
```rust
54-
#[gdnative::export]
55-
fn create_enemy(&mut self, _owner: &gd::Node) -> Enemy {...}
54+
#[export]
55+
fn create_enemy(&mut self, _owner: &Node) -> Enemy {...}
5656
```
5757
Instead, you can wrap the object in a `Instance<Enemy, Unique>`, using `emplace()`. For an in-depth explanation of the `Instance` class, read [this section](http://localhost:3000/gdnative-overview/wrappers.html#instance-reference-with-attached-rust-class).
5858
```rust
59-
#[gdnative::export]
59+
#[export]
6060
fn create_enemy(
6161
&self,
62-
_owner: &gd::Node
63-
) -> gd::Instance<Enemy, gd::thread_access::Unique> {
62+
_owner: &Node
63+
) -> Instance<Enemy, Unique> {
6464
let enemy = Enemy {
65-
pos: gd::Vector2::new(7.0, 2.0),
65+
pos: Vector2::new(7.0, 2.0),
6666
health: 100.0,
6767
name: "MyEnemy".to_string(),
6868
};

src/rust-binding/classes.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ This workflow implies that when you want to execute Rust code, you need to first
1111

1212
Somewhere in your code, usually in `lib.rs`, you need to declare the functions that will be called by the engine when the native library is loaded and unloaded, as well as the registration function for native classes exposed to the engine. godot-rust provides the following macros (consult [their documentation](https://docs.rs/gdnative/latest/gdnative/index.html#macros) for further info and customization):
1313
```rust
14-
gd::godot_gdnative_init!();
15-
gd::godot_nativescript_init!(init);
16-
gd::godot_gdnative_terminate!();
14+
godot_gdnative_init!();
15+
godot_nativescript_init!(init);
16+
godot_gdnative_terminate!();
1717
```
1818
Or the equivalent short-hand:
1919
```rust
@@ -25,7 +25,7 @@ The argument `init` refers to the function registering native script classes, wh
2525
// see details later
2626
struct GodotApi { ... }
2727

28-
fn init(handle: gd::nativescript::InitHandle) {
28+
fn init(handle: InitHandle) {
2929
handle.add_class::<GodotApi>();
3030
}
3131
```
@@ -37,30 +37,30 @@ Similar to the [Hello World](../getting-started/hello-world.md#overriding-a-godo
3737
```rust
3838
// Tell godot-rust that this struct is exported as a native class
3939
// (implements NativeClass trait)
40-
#[derive(gd::nativescript::NativeClass)]
40+
#[derive(NativeClass)]
4141

4242
// Specify the base class (corresponds to 'extends' statement in GDScript).
4343
// * Like 'extends' in GDScript, this can be omitted.
4444
// In that case, the 'Reference' class is used as a base.
4545
// * Unlike 'extends' however, only existing Godot types are permitted,
4646
// no other user-defined scripts.
47-
#[inherit(gd::api::Node)]
47+
#[inherit(Node)]
4848
pub struct GodotApi {}
4949

5050
// Exactly one impl block can have the #[methods] annotation,
5151
// which registers methods in the background.
52-
#[gd::methods]
52+
#[methods]
5353
impl GodotApi {
5454
// Constructor, either:
55-
fn new(owner: &gd::api::Node) -> Self { ... }
55+
fn new(owner: &Node) -> Self { ... }
5656
// or:
57-
fn new(owner: gd::TRef<gd::api::Node>) -> Self { ... }
57+
fn new(owner: TRef<Node>) -> Self { ... }
5858
}
5959
```
6060

6161
The [`#[derive(NativeClass)]` macro](https://docs.rs/gdnative/latest/gdnative/derive.NativeClass.html) enables a Rust type to be usable as a _native class_ in Godot. It implements [the `NativeClass` trait](https://docs.rs/gdnative/latest/gdnative/nativescript/trait.NativeClass.html), which fills in the glue code required to make the class available in Godot. Among other information, this includes class name and registry of exported methods and properties. For the user, the utility methods `new_instance()` and `emplace()` are provided for constructing `Instance` objects.
6262

63-
The function `new()` corresponds to `_init()` in GDScript. The _owner_ is the base object of the script, and must correspond to the class specified in the `#[inherit]` attribute (or `gd::api::Reference` if the attribute is absent). The parameter can be a shared reference `&T` or a `TRef<T>`.
63+
The function `new()` corresponds to `_init()` in GDScript. The _owner_ is the base object of the script, and must correspond to the class specified in the `#[inherit]` attribute (or `Reference` if the attribute is absent). The parameter can be a shared reference `&T` or a `TRef<T>`.
6464

6565
With a `new()` method, you are able to write `GodotApi.new()` in GDScript. If you don't need this, you can add the `#[no_constructor]` attribute to the struct declaration.
6666

src/rust-binding/methods.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,44 @@ In order to receive data from Godot, you can export methods. With the `#[export]
55
The exported method's first parameter is always `&self` or `&mut self` (operating on the Rust object), and the second parameter is `&T` or `TRef<T>` (operating on the Godot base object, with `T` being the inherited type).
66

77
```rust
8-
#[derive(gd::nativescript::NativeClass)]
9-
#[inherit(gd::api::Node)]
8+
#[derive(NativeClass)]
9+
#[inherit(Node)]
1010
pub struct GodotApi {
1111
enemy_count: i32,
1212
}
1313

14-
#[gd::methods]
14+
#[methods]
1515
impl GodotApi {
16-
fn new(_owner: &gd::api::Node) -> Self {
16+
fn new(_owner: &Node) -> Self {
1717
// Print to both shell and Godot editor console
18-
gd::godot_print!("_init()");
18+
godot_print!("_init()");
1919
Self { enemy_count: 0 }
2020
}
2121

22-
#[gd::export]
22+
#[export]
2323
fn create_enemy(
2424
&mut self,
25-
_owner: &gd::api::Node,
25+
_owner: &Node,
2626
typ: String,
27-
pos: gd::core_types::Vector2
27+
pos: Vector2
2828
) {
29-
gd::godot_print!("create_enemy(): type '{}' at position {:?}", typ, pos);
29+
godot_print!("create_enemy(): type '{}' at position {:?}", typ, pos);
3030
self.enemy_count += 1;
3131
}
3232

33-
#[gd::export]
33+
#[export]
3434
fn create_enemy2(
3535
&mut self,
36-
_owner: &gd::api::Node,
37-
typ: gd::core_types::GodotString,
38-
pos: gd::core_types::Variant
36+
_owner: &Node,
37+
typ: GodotString,
38+
pos: Variant
3939
) {
40-
gd::godot_print!("create_enemy2(): type '{}' at position {:?}", typ, pos);
40+
godot_print!("create_enemy2(): type '{}' at position {:?}", typ, pos);
4141
self.enemy_count += 1;
4242
}
4343

44-
#[gd::export]
45-
fn count_enemies(&self, _owner: &gd::api::Node) -> i32 {
44+
#[export]
45+
fn count_enemies(&self, _owner: &Node) -> i32 {
4646
self.enemy_count
4747
}
4848
}
@@ -77,34 +77,34 @@ The above examples have dealt with simple types such as strings and integers. Wh
7777

7878
Let's say we want to pass in an enemy from GDScript, instead of creating one locally. It could be represented by the `Node2D` class and directly configured in the Godot editor. What you then would do is use [the `Ref` wrapper](../gdnative-overview/wrappers.md):
7979
```rust
80-
#[derive(gd::nativescript::NativeClass)]
81-
#[inherit(gd::api::Node)]
80+
#[derive(NativeClass)]
81+
#[inherit(Node)]
8282
pub struct GodotApi {
8383
// Store references to all enemy nodes
84-
enemies: Vec<gd::Ref<gd::api::Node2D>>,
84+
enemies: Vec<Ref<Node2D>>,
8585
}
8686

87-
#[gd::methods]
87+
#[methods]
8888
impl GodotApi {
8989
// new() etc...
9090

91-
#[gd::export]
91+
#[export]
9292
fn add_enemy(
9393
&mut self,
94-
_owner: &gd::Node,
95-
enemy: gd::Ref<gd::api::Node2D> // pass in enemy
94+
_owner: &Node,
95+
enemy: Ref<Node2D> // pass in enemy
9696
) {
9797
self.enemies.push(enemy);
9898
}
9999

100100
// You can even return the enemies directly with Vec.
101101
// In GDScript, you will get an array of nodes.
102102
// An alternative would be VariantArray, able to hold different types.
103-
#[gd::export]
103+
#[export]
104104
fn get_enemies(
105105
&self,
106-
_owner: &gd::api::Node
107-
) -> Vec<gd::Ref<gd::api::Node2D>> {
106+
_owner: &Node
107+
) -> Vec<Ref<Node2D>> {
108108
self.enemies.clone()
109109
}
110110
}
@@ -116,20 +116,20 @@ Godot offers some special methods. Most of them implement [notifications](https:
116116

117117
If you need to override a Godot special method, just declare it as a normal exported method, with the same name and signature as in GDScript:
118118
```rust
119-
#[gd::export]
120-
fn _ready(&mut self, _owner: &gd::Node) {...}
119+
#[export]
120+
fn _ready(&mut self, _owner: &Node) {...}
121121

122-
#[gd::export]
123-
fn _process(&mut self, _owner: &gd::Node, delta: f32) {...}
122+
#[export]
123+
fn _process(&mut self, _owner: &Node, delta: f32) {...}
124124

125-
#[gd::export]
126-
fn _physics_process(&mut self, _owner: &gd::Node, delta: f32) {...}
125+
#[export]
126+
fn _physics_process(&mut self, _owner: &Node, delta: f32) {...}
127127
```
128128

129129
If you want to change how GDScript's default formatter in functions like `str()` or `print()` works, you can overload the `to_string` GDScript method, which corresponds to the following Rust method:
130130
```rust
131-
#[gd::export]
132-
fn _to_string(&self, _owner: &gd::Reference) -> String {...}
131+
#[export]
132+
fn _to_string(&self, _owner: &Reference) -> String {...}
133133
```
134134

135135

src/rust-binding/properties.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Like methods, properties can be exported. The `#[property]` attribute above a fi
44

55
In the previous example, we could replace the `count_enemies()` method with a property `enemy_count`.
66
```rust
7-
#[derive(gd::nativescript::NativeClass)]
8-
#[inherit(gd::api::Node)]
7+
#[derive(NativeClass)]
8+
#[inherit(Node)]
99
pub struct GodotApi {
1010
#[property]
1111
enemy_count: i32,

0 commit comments

Comments
 (0)