Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
RUSTFLAGS: "-D warnings"
strategy:
matrix:
api_version: ["4-1", "4-2", "4-3", "4-4"]
api_version: ["4-2", "4-3", "4-4", "4-5"]

steps:
- name: Checkout
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
runs-on: "ubuntu-22.04"
strategy:
matrix:
api_version: ["4-1", "4-2", "4-3", "4-4"]
api_version: ["4-2", "4-3", "4-4", "4-5"]

steps:
- name: Checkout
Expand All @@ -75,7 +75,7 @@ jobs:
runs-on: "ubuntu-22.04"
strategy:
matrix:
api_version: ["4-1", "4-2", "4-3", "4-4", "custom"]
api_version: ["4-2", "4-3", "4-4", "4-5", "custom"]

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
RUSTFLAGS: "-D warnings"
strategy:
matrix:
api_version: ["4-1", "4-2", "4-3", "4-4"]
api_version: ["4-2", "4-3", "4-4", "4-5"]

steps:
- name: Checkout
Expand Down
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ version = "0.1.0"
edition = "2021"

[workspace.dependencies]
godot = { version = "0.3.2", features = ["experimental-threads"] }
godot-cell = "0.3"
godot-bindings = "0.3"
godot = { version = ">=0.4.1", features = ["experimental-threads"] }
godot-cell = "0.4.0"
godot-bindings = "0.4.0"
itertools = "0.10"
rand = "0.8"
darling = { version = "0.20" }
Expand Down
2 changes: 1 addition & 1 deletion derive/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn script_enum_derive(input: proc_macro::TokenStream) -> proc_macro::TokenSt
}

impl #godot_types::meta::ToGodot for #enum_ident {
type ToVia<'a> = Self::Via;
type Pass = ::godot::meta::ByValue;

fn to_godot(&self) -> Self::Via {
#enum_from_self::from(self)
Expand Down
14 changes: 7 additions & 7 deletions derive/src/impl_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn godot_script_impl(
let godot_types = godot_types();
let string_name_ty = string_name_ty();
let variant_ty = variant_ty();
let call_error_ty = quote!(#godot_types::sys::GDExtensionCallErrorType);
let call_error_ty = quote!(#godot_types::meta::error::CallErrorType);
let property_hints = property_hints();

let current_type = &body.self_ty;
Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn godot_script_impl(
::godot_rust_script::private_export::RustScriptPropDesc {
name: stringify!(#arg_name),
ty: #arg_type,
class_name: <<#arg_rust_type as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
class_name: <<#arg_rust_type as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_id(),
exported: false,
hint: #property_hints::NONE,
hint_string: String::new(),
Expand All @@ -84,10 +84,10 @@ pub fn godot_script_impl(
quote_spanned! {
arg.span() =>
#godot_types::prelude::FromGodot::try_from_variant(
args.get(#index).ok_or(#godot_types::sys::GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS)?
args.get(#index).ok_or(#call_error_ty::TooFewArguments)?
).map_err(|err| {
#godot_types::global::godot_error!("failed to convert variant for argument {} of {}: {}", stringify!(#arg_name), #fn_name_str, err);
#godot_types::sys::GDEXTENSION_CALL_ERROR_INVALID_ARGUMENT
#call_error_ty::InvalidArgument
})?,
}
)
Expand All @@ -104,7 +104,7 @@ pub fn godot_script_impl(
fnc.span() =>
#fn_name_str => {
if args.len() > #arg_count {
return Err(#godot_types::sys::GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS);
return Err(#call_error_ty::TooManyArguments);
}

Ok(#godot_types::prelude::ToGodot::to_variant(&self.#fn_name(#args)))
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn godot_script_impl(
return_type: ::godot_rust_script::private_export::RustScriptPropDesc {
name: #fn_name_str,
ty: #fn_return_ty,
class_name: <<#fn_return_ty_rust as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
class_name: <<#fn_return_ty_rust as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_id(),
exported: false,
hint: #property_hints::NONE,
hint_string: String::new(),
Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn godot_script_impl(
match name.to_string().as_str() {
#method_dispatch

_ => Err(#godot_types::sys::GDEXTENSION_CALL_ERROR_INVALID_METHOD),
_ => Err(#call_error_ty::InvalidMethod),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let godot_types = godot_types();
let variant_ty = variant_ty();
let string_name_ty = string_name_ty();
let call_error_ty = quote!(#godot_types::sys::GDExtensionCallErrorType);
let call_error_ty = quote!(#godot_types::meta::error::CallErrorType);

let base_class = opts
.base
Expand Down Expand Up @@ -409,7 +409,7 @@ fn derive_field_metadata(
::godot_rust_script::private_export::RustScriptPropDesc {
name: #name,
ty: #ty,
class_name: <<#rust_ty as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
class_name: <<#rust_ty as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_id(),
exported: #is_exported,
hint: #hint,
hint_string: #hint_string,
Expand Down
7 changes: 4 additions & 3 deletions rust-script/src/editor_ui_hacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

use godot::classes::{EditorInterface, Engine};
use godot::global::godot_warn;
use godot::meta::ToGodot;
use godot::meta::{ByValue, ToGodot};
use godot::obj::Singleton as _;
use godot::prelude::GodotConvert;

#[derive(Clone, Copy)]
Expand All @@ -29,9 +30,9 @@ impl GodotConvert for EditorToasterSeverity {
}

impl ToGodot for EditorToasterSeverity {
type ToVia<'v> = Self::Via;
type Pass = ByValue;

fn to_godot(&self) -> Self::ToVia<'static> {
fn to_godot(&self) -> Self::Via {
(*self).into()
}
}
Expand Down
27 changes: 13 additions & 14 deletions rust-script/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::{collections::HashMap, fmt::Debug};

use godot::meta::{FromGodot, GodotConvert, ToGodot};
use godot::meta::error::CallErrorType;
use godot::meta::{ByValue, FromGodot, GodotConvert, ToGodot};
use godot::obj::Inherits;
use godot::prelude::{ConvertError, Gd, Object, StringName, Variant};

pub use crate::runtime::Context;
use crate::runtime::RustScript;

pub use export::GodotScriptExport;
pub use on_editor::OnEditor;
Expand All @@ -35,7 +37,7 @@ pub trait GodotScript: Debug + GodotScriptImpl<ImplBase = Self::Base> {
method: StringName,
args: &[&Variant],
context: Context<'_, Self>,
) -> Result<Variant, godot::sys::GDExtensionCallErrorType>;
) -> Result<Variant, CallErrorType>;

fn to_string(&self) -> String;
fn property_state(&self) -> HashMap<StringName, Variant>;
Expand All @@ -51,7 +53,7 @@ pub trait GodotScriptImpl {
name: StringName,
args: &[&Variant],
context: Context<Self>,
) -> Result<Variant, godot::sys::GDExtensionCallErrorType>;
) -> Result<Variant, godot::meta::error::CallErrorType>;
}

#[derive(Debug)]
Expand All @@ -72,7 +74,8 @@ impl<T: GodotScript> RsRef<T> {
let script = owner
.upcast_ref::<Object>()
.get_script()
.try_to::<Option<Gd<crate::runtime::RustScript>>>();
.map(|script| script.try_cast::<RustScript>())
.transpose();

let Ok(script) = script else {
return Some(GodotScriptCastError::NotRustScript);
Expand Down Expand Up @@ -127,20 +130,16 @@ where
}

impl<T: GodotScript> ToGodot for RsRef<T> {
type ToVia<'v>
= Gd<T::Base>
where
Self: 'v;
type Pass = ByValue;

fn to_godot(&self) -> Self::ToVia<'_> {
fn to_godot(&self) -> Self::Via {
self.deref().clone()
}
}

impl<'v, T: GodotScript> ::godot::prelude::Var for RsRef<T>
impl<T: GodotScript> ::godot::prelude::Var for RsRef<T>
where
Self: GodotConvert<Via = <Self as ToGodot>::ToVia<'v>>,
Self: 'v,
Self: GodotConvert,
{
fn get_property(&self) -> Self::Via {
<Self as ToGodot>::to_godot(self)
Expand Down Expand Up @@ -193,7 +192,7 @@ impl<T: GodotScript, B: Inherits<T::Base> + Inherits<Object>> CastToScript<T> fo
self.try_to_script().unwrap_or_else(|err| {
panic!(
"`{}` was assumed to have rust script `{}`, but this was not the case at runtime!\nError: {}",
B::class_name(),
B::class_id(),
T::CLASS_NAME,
err,
);
Expand All @@ -204,7 +203,7 @@ impl<T: GodotScript, B: Inherits<T::Base> + Inherits<Object>> CastToScript<T> fo
self.try_into_script().unwrap_or_else(|err| {
panic!(
"`{}` was assumed to have rust script `{}`, but this was not the case at runtime!\nError: {}",
B::class_name(),
B::class_id(),
T::CLASS_NAME,
err
);
Expand Down
2 changes: 1 addition & 1 deletion rust-script/src/interface/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<T: GodotClass> GodotScriptExport for Gd<T> {
return custom;
}

T::class_name().to_string()
T::class_id().to_string()
}

fn hint(custom: Option<PropertyHint>) -> PropertyHint {
Expand Down
5 changes: 3 additions & 2 deletions rust-script/src/interface/on_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ where

impl<T> godot::prelude::Var for OnEditor<T>
where
for<'v> T: ToGodot<ToVia<'v> = <T as GodotConvert>::Via> + FromGodot + 'v,
for<'v> T: ToGodot + FromGodot + 'v,
Self: GodotConvert<Via = Option<T::Via>>,
T::Via: Clone,
{
fn get_property(&self) -> Self::Via {
match self.value {
ValueState::Invalid => None,
ValueState::Valid(ref value) => Some(value.to_godot()),
ValueState::Valid(ref value) => Some(value.to_godot_owned()),
}
}

Expand Down
9 changes: 3 additions & 6 deletions rust-script/src/interface/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use godot::builtin::{
};
use godot::classes::Object;
use godot::global::{Error, PropertyHint};
use godot::meta::{GodotConvert, GodotType, ToGodot};
use godot::meta::{ByValue, GodotConvert, GodotType, ToGodot};
use godot::obj::{Gd, GodotClass};

use crate::static_script_registry::RustScriptPropDesc;
Expand Down Expand Up @@ -112,7 +112,7 @@ macro_rules! signal_argument_desc {
RustScriptPropDesc {
name: $name,
ty: <<<$type as GodotConvert>::Via as GodotType>::Ffi as godot::sys::GodotFfi>::VARIANT_TYPE.variant_as_nil(),
class_name: <<$type as GodotConvert>::Via as GodotType>::class_name(),
class_name: <<$type as GodotConvert>::Via as GodotType>::class_id(),
exported: false,
hint: PropertyHint::NONE,
hint_string: String::new(),
Expand Down Expand Up @@ -213,10 +213,7 @@ impl<T: SignalArguments> GodotConvert for ScriptSignal<T> {
}

impl<T: SignalArguments> ToGodot for ScriptSignal<T> {
type ToVia<'v>
= Self::Via
where
Self: 'v;
type Pass = ByValue;

fn to_godot(&self) -> Self::Via {
godot::builtin::Signal::from_object_signal(&self.host, self.name)
Expand Down
2 changes: 1 addition & 1 deletion rust-script/src/runtime/downgrade_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ where
{
fn downgrade_gd<F: FnOnce(Gd<Self>) -> R, R>(&mut self, closure: F) -> R {
let mut_base = self.base_mut();
let self_gd = mut_base.to_godot().cast();
let self_gd = mut_base.to_godot_owned().cast();

closure(self_gd)
}
Expand Down
Loading
Loading