Skip to content

Commit 7198e57

Browse files
committed
Documentation
1 parent 1c0d080 commit 7198e57

File tree

12 files changed

+237
-4
lines changed

12 files changed

+237
-4
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ thiserror = "1"
2424

2525
godot-rust-script-derive = { path = "derive" }
2626
tests-scripts-lib = { path = "tests-scripts-lib" }
27+
28+
[workspace.lints.rust]
29+
missing_docs = "warn"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ For this, a manual implementation of the `godot::init::ExtensionLibrary` trait i
4646
be achieved via two macro calls. The `init!(...)` macro requires the name / path to a module in your library, which represents the root module
4747
of all available scripts.
4848

49-
```rs
49+
```rust
5050
struct Lib;
5151

5252
#[gdextension]
@@ -75,7 +75,7 @@ unsafe impl ExtensionLibrary for Lib {
7575

7676
Rust scripts require a root module. All rust modules under this module will be considered as potential scripts.
7777

78-
```rs
78+
```rust
7979
mod example_script;
8080

8181
godot_rust_script::define_script_root!();
@@ -92,7 +92,7 @@ Scripts are then composed of a `struct` definition and an `impl` block. Public f
9292
other scripting languages and the engine, so they must use Godot compatible types. The same applies to struct fields.
9393
Struct fields can additionally be exported via the `#[export]` attribute, so they show up in the editor inspector.
9494

95-
```rs
95+
```rust
9696
use godot_rust_script::{
9797
godot::prelude::{godot_print, Gd, GodotString, Node3D, Object},
9898
godot_script_impl, GodotScript,

derive/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ proc-macro2.workspace = true
1212
quote.workspace = true
1313
syn.workspace = true
1414
itertools.workspace = true
15+
16+
[lints]
17+
workspace = true

derive/src/lib.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* License, v. 2.0. If a copy of the MPL was not distributed with this
44
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
55
*/
6+
#![doc = "Derive macros for the godot-rust-script crate."]
67

78
mod attribute_ops;
89
mod enums;
@@ -19,6 +20,60 @@ use type_paths::{godot_types, property_hints, string_name_ty, variant_ty};
1920

2021
use crate::attribute_ops::{FieldExportOps, FieldSignalOps, PropertyOpts};
2122

23+
/// Use this derive macro to create new rust scripts for your projects.
24+
///
25+
/// The macro is desinged to closely align with both godot-rusts [`GodotClass`](https://docs.rs/godot/latest/godot/prelude/derive.GodotClass.html) macro and the GDScript
26+
/// annotations.
27+
///
28+
/// # Top Level Attribute
29+
/// On the struct level the `#[script]` attribute can be used to configure base details of the script.
30+
///
31+
/// ## `#[script(base)]`
32+
/// ```
33+
/// # use ::godot_rust_script::{GodotScript, godot_script_impl};
34+
/// # use ::godot::classes::Node3D;
35+
/// #
36+
/// #[derive(GodotScript, Debug)]
37+
/// #[script(base = Node3D)]
38+
/// struct MyScript {}
39+
///
40+
/// # #[godot_script_impl]
41+
/// # impl MyScript {}
42+
/// ```
43+
///
44+
/// Set the `base` field to specify a base class your script should inherit from. By default all scripts inherit from [`RefCounted`](https://docs.rs/godot/latest/godot/classes/struct.RefCounted.html).
45+
///
46+
/// # Field Level Attributes
47+
/// On the field level you can specify customizations for your script properties. Fields that are private will not be exposed to the engine.
48+
/// Public field on the other hand are exposed to the engine and can be annotated with attributes.
49+
///
50+
/// ## `#[prop]`
51+
/// Use the `#[prop]` attribute to set up getter and setter functions for your properties.
52+
///
53+
/// ```
54+
/// # use godot_rust_script::{GodotScript, godot_script_impl};
55+
/// # use godot::builtin::GString;
56+
/// #
57+
/// #[derive(GodotScript, Debug)]
58+
/// struct MyScript {
59+
/// #[prop(set = Self::set_my_prop, get = Self::get_my_prop)]
60+
/// my_prop: GString,
61+
/// }
62+
///
63+
/// #[godot_script_impl]
64+
/// impl MyScript {
65+
/// fn set_my_prop(&mut self, value: GString) {
66+
/// self.my_prop = value;
67+
/// }
68+
///
69+
/// fn get_my_prop(&self) -> GString {
70+
/// self.my_prop.clone()
71+
/// }
72+
/// }
73+
/// ```
74+
///
75+
/// This attribute optionally accepts a `get` and a `set` field. If these fields are defined they have to be set to a function pointer
76+
/// expression. The expression can contain the `Self` keyword.
2277
#[proc_macro_derive(GodotScript, attributes(export, script, prop, signal))]
2378
pub fn derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
2479
let input = parse_macro_input!(input as DeriveInput);
@@ -502,6 +557,7 @@ fn derive_signal_metadata(field: &SpannedValue<FieldOpts>) -> (TokenStream, Toke
502557
(metadata, const_assert.unwrap_or_default())
503558
}
504559

560+
/// Attribute for `GodotScript` impls to automatically implement the corret traits.
505561
#[proc_macro_attribute]
506562
pub fn godot_script_impl(
507563
args: proc_macro::TokenStream,
@@ -544,6 +600,7 @@ fn extract_ident_from_type(impl_target: &syn::Type) -> Result<Ident, TokenStream
544600
}
545601
}
546602

603+
/// Derive macro to auto implement `GodotScriptEnum`
547604
#[proc_macro_derive(GodotScriptEnum, attributes(script_enum))]
548605
pub fn script_enum_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
549606
enums::script_enum_derive(input)

rust-script/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ godot-bindings.workspace = true
2828
default = ["runtime", "scripts"]
2929
runtime = ["dep:itertools", "dep:rand"]
3030
scripts = ["dep:godot-rust-script-derive"]
31+
32+
[lints]
33+
workspace = true

rust-script/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* License, v. 2.0. If a copy of the MPL was not distributed with this
44
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
55
*/
6+
#![doc = "Build script for the godot-rust-script crate."]
67

78
fn main() {
89
godot_bindings::emit_godot_version_cfg();

0 commit comments

Comments
 (0)