Skip to content

Commit 2345ac2

Browse files
authored
Merge pull request #52 from bluenote10/few_minor_fixes
Minor fixes to style, links and formatting.
2 parents 1cc1439 + cc6e884 commit 2345ac2

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/exporting/macosx.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,5 @@ Double-check your `.dylib` file is there.
137137

138138
## Useful links
139139

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

src/faq/code.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl SignalEmitter {
4040
}
4141
```
4242

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.
4444

4545
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.
4646

@@ -85,19 +85,23 @@ Here is an example of some common `unsafe` usage that you will often see and use
8585
fn get_a_node(&self, owner: TRef<Node>) {
8686
// This is safe because it returns an option that Rust knows how to check.
8787
let child = 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.
8989
let child = child.expect("I know this should exist");
9090
// This is also safe because Rust panics if the returned `Option` is None.
9191
let child = child.cast_instance::<Foo>().expect("I know that it must be this type");
9292
// 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
94+
// it gets used.
9495
let child: Instance<Foo> = unsafe { child.assume_safe() };
95-
// 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.
9799
child.map_mut(|c, o| {
98100
c.bar(o);
99101
}).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.
101105
unsafe {
102106
child.call("bar", &[])
103107
};
@@ -171,14 +175,14 @@ impl EntityFactory {
171175
}
172176
}
173177
```
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.
175179
This still needs an extra type `EntityFactory`, however you could reuse that for multiple classes.
176180

177181

178182
## How can I implement static methods in GDNative?
179183

180184
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.
182186

183187
As a work-around, it is possible to use a ZST (zero-sized type):
184188

@@ -207,7 +211,7 @@ Good places for instantiation are for instance:
207211
- as a [singleton auto-load object](https://docs.godotengine.org/en/stable/getting_started/step_by_step/singletons_autoload.html).
208212

209213

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?
211215

212216
Assuming that a method takes an argument `my_node` as a `Variant`
213217

@@ -235,7 +239,7 @@ impl AnotherNativeScript {
235239
.expect("Failed to convert my_node variant to object")
236240
.assume_safe()
237241
};
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.
239243
let my_node = my_node
240244
.cast_instance::<MyNode2D>()
241245
.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
279283

280284
## How do I keep a reference of `Node`?
281285

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>>`.
283287

284288
For example, in the following GDScript code
285289
```gdscript
@@ -357,7 +361,7 @@ impl MyNode {
357361
let instance = node2d.cast::<Node2D>();
358362
let instance = godot_egui.cast_instance::<MyClass>()
359363
.expect("child `MyNode2D` must be type `MyClass`");
360-
364+
361365
self.instance = Some(instance.claim());
362366
}
363367
}
@@ -417,6 +421,6 @@ impl MyClass {
417421

418422
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.
419423

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.
421425

422426
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

Comments
 (0)