Skip to content

Commit

Permalink
adds doc for log.rs
Browse files Browse the repository at this point in the history
and doc test for bind.rs
  • Loading branch information
Astrale committed Mar 7, 2023
1 parent 7d42ebb commit 08a2880
Show file tree
Hide file tree
Showing 2 changed files with 70 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
///
/// ## Example with `RefCounted` as a base
///
/// ```
/// 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 use MyStruct in GDScript for instance by calling
/// `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.
///
/// ## Example with `Node` as a Base
///
/// ```
/// 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
10 changes: 10 additions & 0 deletions godot-core/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

/// Pushes a warning message to Godot's built-in debugger and to the OS terminal.
///
/// _Godot equivalent: @GlobalScope.push_warning()_
#[macro_export]
macro_rules! godot_warn {
($fmt:literal $(, $args:expr)* $(,)?) => {
Expand All @@ -21,6 +24,9 @@ macro_rules! godot_warn {
};
}

/// Pushes an error message to Godot's built-in debugger and to the OS terminal.
///
/// _Godot equivalent: @GlobalScope.push_error()_
#[macro_export]
macro_rules! godot_error {
// FIXME expr needs to be parenthesised, see usages
Expand Down Expand Up @@ -57,6 +63,9 @@ macro_rules! godot_script_error {
};
}

/// Prints to the Godot console.
///
/// _Godot equivalent: @GlobalScope.print()_
#[macro_export]
macro_rules! godot_print {
($fmt:literal $(, $args:expr)* $(,)?) => {
Expand All @@ -75,6 +84,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, used by the godot_print! macro.
pub fn print(varargs: &[Variant]) {
unsafe {
let method_name = StringName::from("print");
Expand Down

0 comments on commit 08a2880

Please sign in to comment.