Skip to content

Commit 3076a61

Browse files
committed
Documentation
1 parent 94edf15 commit 3076a61

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

rust-script/src/interface.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ pub use crate::runtime::Context;
2020
pub use export::GodotScriptExport;
2121
pub use signals::{ScriptSignal, Signal};
2222

23+
/// The primary trait of this library. This trait must be implemented by a struct to create a new rust script.
24+
///
25+
/// While it is possible, it's not intended that this trait is implemented by hand. Use the [derive macro](derive@crate::GodotScript) to
26+
/// implement this trait.
2327
pub trait GodotScript: Debug + GodotScriptImpl<ImplBase = Self::Base> {
2428
type Base: Inherits<Object>;
2529

@@ -171,6 +175,21 @@ impl<T: GodotScript, B: Inherits<T::Base> + Inherits<Object>> CastToScript<T> fo
171175
}
172176
}
173177

178+
/// Defines the root module for rust scripts. All scripts must be in submodules of the root module.
179+
///
180+
/// There must be a script root module in your project for Godot Rust Script to work. Using multiple root modules is currently not supported.
181+
///
182+
/// # Example
183+
/// ```no_compile
184+
/// # use godot_rust_script::define_script_root;
185+
/// // Example script root: src/scripts/mod.rs
186+
///
187+
/// // define your script modules that contain `RustScript` structs.
188+
/// // mod player;
189+
/// // mod mob;
190+
///
191+
/// define_script_root!();
192+
/// ```
174193
#[macro_export]
175194
macro_rules! define_script_root {
176195
() => {
@@ -202,6 +221,7 @@ macro_rules! define_script_root {
202221
};
203222
}
204223

224+
/// DEPRECATED: This macro has been renamed to [define_script_root].
205225
#[deprecated = "Has been renamed to define_script_root!()"]
206226
#[macro_export]
207227
macro_rules! setup_library {
@@ -212,6 +232,7 @@ macro_rules! setup_library {
212232

213233
pub trait GodotScriptEnum: GodotConvert + FromGodot + ToGodot {}
214234

235+
#[doc(hidden)]
215236
#[macro_export]
216237
macro_rules! init {
217238
($scripts_module:tt) => {
@@ -222,6 +243,7 @@ macro_rules! init {
222243
};
223244
}
224245

246+
#[doc(hidden)]
225247
#[macro_export]
226248
macro_rules! deinit {
227249
() => {

rust-script/src/lib.rs

Lines changed: 58 additions & 1 deletion
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 = include_str!("../../README.md")]
67

78
mod apply;
89

@@ -11,7 +12,63 @@ mod interface;
1112
mod runtime;
1213
mod static_script_registry;
1314

14-
pub use godot_rust_script_derive::{godot_script_impl, GodotScript, GodotScriptEnum};
15+
pub use godot_rust_script_derive::{godot_script_impl, GodotScriptEnum};
16+
17+
/// Use this derive macro to create new rust scripts for your projects.
18+
///
19+
/// 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
20+
/// annotations.
21+
///
22+
/// # Top Level Attribute
23+
/// On the struct level the `#[script]` attribute can be used to configure base details of the script.
24+
///
25+
/// ## `#[script(base)]`
26+
/// ```
27+
/// # use godot_rust_script::{GodotScript, godot_script_impl};
28+
/// # use godot::classes::Node3D;
29+
/// #
30+
/// #[derive(GodotScript, Debug)]
31+
/// #[script(base = Node3D)]
32+
/// struct MyScript {}
33+
///
34+
/// # #[godot_script_impl]
35+
/// # impl MyScript {}
36+
/// ```
37+
///
38+
/// 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).
39+
///
40+
/// # Field Level Attributes
41+
/// On the field level you can specify customizations for your script properties. Fields that are private will not be exposed to the engine.
42+
/// Public field on the other hand are exposed to the engine and can be annotated with attributes.
43+
///
44+
/// ## `#[prop]`
45+
/// Use the `#[prop]` attribute to set up getter and setter functions for your properties.
46+
///
47+
/// ```
48+
/// # use godot_rust_script::{GodotScript, godot_script_impl};
49+
/// # use godot::builtin::GString;
50+
/// #
51+
/// #[derive(GodotScript, Debug)]
52+
/// struct MyScript {
53+
/// #[prop(set = Self::set_my_prop, get = Self::get_my_prop)]
54+
/// my_prop: GString,
55+
/// }
56+
///
57+
/// #[godot_script_impl]
58+
/// impl MyScript {
59+
/// fn set_my_prop(&mut self, value: GString) {
60+
/// self.my_prop = value;
61+
/// }
62+
///
63+
/// fn get_my_prop(&self) -> GString {
64+
/// self.my_prop.clone()
65+
/// }
66+
/// }
67+
/// ```
68+
///
69+
/// This attribute optionally accepts a `get` and a `set` field. If these fields are defined they have to be set to a function pointer
70+
/// expression. The expression can contain the `Self` keyword.
71+
pub use godot_rust_script_derive::GodotScript;
1572
pub use interface::*;
1673
pub use runtime::RustScriptExtensionLayer;
1774

rust-script/src/static_script_registry.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::runtime::GodotScriptObject;
2121

2222
godot::sys::plugin_registry!(pub SCRIPT_REGISTRY: RegistryItem);
2323

24+
#[doc(hidden)]
2425
#[macro_export]
2526
#[cfg(before_api = "4.4")]
2627
macro_rules! register_script_class {
@@ -44,6 +45,7 @@ macro_rules! register_script_class {
4445
};
4546
}
4647

48+
#[doc(hidden)]
4749
#[macro_export]
4850
#[cfg(since_api = "4.4")]
4951
macro_rules! register_script_class {
@@ -66,6 +68,7 @@ macro_rules! register_script_class {
6668
};
6769
}
6870

71+
#[doc(hidden)]
6972
#[macro_export]
7073
macro_rules! register_script_methods {
7174
($class_name:ty, $methods:expr) => {

0 commit comments

Comments
 (0)