You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/exporting/macosx.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -137,5 +137,5 @@ Double-check your `.dylib` file is there.
137
137
138
138
## Useful links
139
139
140
-
*https://github.com/tpoechtrager/osxcross: tool used to install the Mac OS X SDK on Linux
141
-
*https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html: a complete tutorial on how to use osxcross
140
+
*[https://github.com/tpoechtrager/osxcross](https://github.com/tpoechtrager/osxcross): tool used to install the Mac OS X SDK on Linux
141
+
*[https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html](https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html): a complete tutorial on how to use osxcross
Copy file name to clipboardExpand all lines: src/faq/code.md
+17-13Lines changed: 17 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ impl SignalEmitter {
40
40
}
41
41
```
42
42
43
-
The assumption with the above code is that `Signaller` is holding data that is too large to be feasible to clone into the signal. So the purpose of the signal is to notify other Nodes or Objects that this the data has been updated.
43
+
The assumption with the above code is that `SignalEmitter` is holding data that is too large to be feasible to clone into the signal. So the purpose of the signal is to notify other Nodes or Objects that this the data has been updated.
44
44
45
45
The problem is that, unless the nodes all connect with the `Object::CONNECT_DEFERRED` flag, they will be notified immediately and will attempt to borrow the data. This is the root cause of the `BorrowFailed` error.
46
46
@@ -85,19 +85,23 @@ Here is an example of some common `unsafe` usage that you will often see and use
85
85
fnget_a_node(&self, owner:TRef<Node>) {
86
86
// This is safe because it returns an option that Rust knows how to check.
87
87
letchild=owner.get_child("foo");
88
-
// This is safe because Rust panics if the returned `Option` is None.
88
+
// This is safe because Rust panics if the returned `Option` is None.
89
89
letchild=child.expect("I know this should exist");
90
90
// This is also safe because Rust panics if the returned `Option` is None.
91
91
letchild=child.cast_instance::<Foo>().expect("I know that it must be this type");
92
92
// This is unsafe because the compiler cannot reason about the lifetime of `child`.
93
-
// It is the programmer's responsibility to ensure that `child` is not freed before it gets used.
93
+
// It is the programmer's responsibility to ensure that `child` is not freed before
// This is safe because we have already asserted above that we are assuming that there should be no problem and Rust
96
-
// can statically analyze the safety of the functions
96
+
// This is safe because we have already asserted above that we are assuming that
97
+
// there should be no problem and Rust can statically analyze the safety of the
98
+
// functions.
97
99
child.map_mut(|c, o| {
98
100
c.bar(o);
99
101
}).expect("this should not fail");
100
-
// This is unsafe because it relies on Godot for function dispatch and it is possible for it to call `Object.free()` or `Reference.unreference()` as well as other native code that may cause undefined behavior.
102
+
// This is unsafe because it relies on Godot for function dispatch and it is
103
+
// possible for it to call `Object.free()` or `Reference.unreference()` as
104
+
// well as other native code that may cause undefined behavior.
101
105
unsafe {
102
106
child.call("bar", &[])
103
107
};
@@ -171,14 +175,14 @@ impl EntityFactory {
171
175
}
172
176
}
173
177
```
174
-
So instead of `Enemy.new()` you can write `EntityFactory.enemy(args)` in GDScript.
178
+
So instead of `Enemy.new()` you can write `EntityFactory.enemy(args)` in GDScript.
175
179
This still needs an extra type `EntityFactory`, however you could reuse that for multiple classes.
176
180
177
181
178
182
## How can I implement static methods in GDNative?
179
183
180
184
In GDScript, classes can have static methods.
181
-
However, due to a limitation of GDNative, static methods are not supported in general.
185
+
However, due to a limitation of GDNative, static methods are not supported in general.
182
186
183
187
As a work-around, it is possible to use a ZST (zero-sized type):
184
188
@@ -207,7 +211,7 @@ Good places for instantiation are for instance:
207
211
- as a [singleton auto-load object](https://docs.godotengine.org/en/stable/getting_started/step_by_step/singletons_autoload.html).
208
212
209
213
210
-
## How to I convert from a `Variant` or other Godot Type to the underlying Rust type?
214
+
## How do I convert from a `Variant` or other Godot Type to the underlying Rust type?
211
215
212
216
Assuming that a method takes an argument `my_node` as a `Variant`
213
217
@@ -235,7 +239,7 @@ impl AnotherNativeScript {
235
239
.expect("Failed to convert my_node variant to object")
236
240
.assume_safe()
237
241
};
238
-
// 2. Obtain a RefInstance which gives acccess to the Rust object's data
242
+
// 2. Obtain a RefInstance which gives access to the Rust object's data.
239
243
letmy_node=my_node
240
244
.cast_instance::<MyNode2D>()
241
245
.expect("Failed to cast my_node object to instance");
@@ -279,7 +283,7 @@ Also, you can always put a Mutex<HashMap> into a Rust static and load everything
279
283
280
284
## How do I keep a reference of `Node`?
281
285
282
-
The idiomatic way to maintain a reference to a node in the SceneTree from Rust is to use `Option<Ref<T>>`.
286
+
The idiomatic way to maintain a reference to a node in the SceneTree from Rust is to use `Option<Ref<T>>`.
283
287
284
288
For example, in the following GDScript code
285
289
```gdscript
@@ -357,7 +361,7 @@ impl MyNode {
357
361
letinstance=node2d.cast::<Node2D>();
358
362
letinstance=godot_egui.cast_instance::<MyClass>()
359
363
.expect("child `MyNode2D` must be type `MyClass`");
360
-
364
+
361
365
self.instance =Some(instance.claim());
362
366
}
363
367
}
@@ -417,6 +421,6 @@ impl MyClass {
417
421
418
422
If you require insight into Rust code that is not exported to Godot or would like more in-depth information regarding how your Rust code is executing, it will be necessary to use a Rust compatible profiler such as [puffin](https://crates.io/crates/puffin) or [perf](https://perf.wiki.kernel.org/index.php/Main_Page). These tools can be used to more accurately determine bottlenecks and the general performance of your Rust code.
419
423
420
-
**Note:** There are many more profilers than the ones listed and you should do your own research before selecting which one you wish to use.
424
+
**Note:** There are many more profilers than the ones listed and you should do your own research before selecting which one you wish to use.
421
425
422
426
For more information about profiling and other rust performance tips, please check out the [Rust performance book](https://nnethercote.github.io/perf-book/profiling.html).
0 commit comments