Skip to content

Commit

Permalink
adds doc tests to Godot Ext
Browse files Browse the repository at this point in the history
adds doc to godot::log::*
  • Loading branch information
Astrale committed Mar 5, 2023
1 parent 72870d1 commit ceda0d2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
60 changes: 60 additions & 0 deletions godot-core/src/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,66 @@ use crate::obj::GodotClass;
///
/// Do not call any of these methods directly -- they are an interface to Godot. Functionality
/// described here is available through other means (e.g. `init` via `Gd::new_default`).
///
/// It is not enough to impl GodotExt to be registered in Godot, for this you should look at [ExtensionLibrary](crate::init::ExtensionLibrary)
///
/// # Examples
///
/// ## Basic Reference
///
/// ```
/// use godot::prelude::*;
///
/// #[derive(GodotClass)]
/// struct MyRef;
///
/// #[godot_api]
/// impl MyRef {
/// #[func]
/// pub fn hello_world(&mut self) {
/// godot_print!("Hello World!")
/// }
/// }
///
/// #[godot_api]
/// impl GodotExt for MyRef {
/// fn init(_: Base<RefCounted>) -> Self {
/// MyRef
/// }
/// }
/// ```
///
/// The following example allows to reference MyStruct in gdscript by calling for instance
/// `MyStruct.new().hello_world()`.
///
///
/// Note that you have to implement init otherwise you won't be able to call new or any
/// other methods from gdscript
///
/// ## Basic Node
///
/// ```
/// use godot::prelude::*;
///
/// #[derive(GodotClass)]
/// #[class(base=Node)]
/// pub struct MyNode {
/// #[base]
/// base: Base<Node>,
/// }
///
///
/// #[godot_api]
/// impl GodotExt for MyNode {
/// fn init(base : Base<Node>) -> Self {
/// MyNode {base}
/// }
/// fn ready(&mut self) {
/// godot_print!("Hello World!");
/// }
/// }
/// ```
#[allow(unused_variables)]
#[allow(clippy::unimplemented)] // TODO consider using panic! with specific message, possibly generated code
pub trait GodotExt: crate::private::You_forgot_the_attribute__godot_api
Expand Down
4 changes: 4 additions & 0 deletions godot-core/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

/// Throws a godot warning
#[macro_export]
macro_rules! godot_warn {
($fmt:literal $(, $args:expr)* $(,)?) => {
Expand All @@ -21,6 +22,7 @@ macro_rules! godot_warn {
};
}

/// Throws a godot error
#[macro_export]
macro_rules! godot_error {
// FIXME expr needs to be parenthesised, see usages
Expand Down Expand Up @@ -57,6 +59,7 @@ macro_rules! godot_script_error {
};
}

/// Prints to the godot console
#[macro_export]
macro_rules! godot_print {
($fmt:literal $(, $args:expr)* $(,)?) => {
Expand All @@ -75,6 +78,7 @@ pub use crate::{godot_error, godot_print, godot_script_error, godot_warn};
use crate::builtin::{StringName, Variant};
use crate::sys::{self, GodotFfi};

/// prints to the godot console, it's use is to be used by the godot_print! macro
pub fn print(varargs: &[Variant]) {
unsafe {
let method_name = StringName::from("print");
Expand Down

0 comments on commit ceda0d2

Please sign in to comment.