diff --git a/godot-core/src/engine/mod.rs b/godot-core/src/engine/mod.rs index 8be55f24e..0be23fa5d 100644 --- a/godot-core/src/engine/mod.rs +++ b/godot-core/src/engine/mod.rs @@ -15,7 +15,7 @@ pub use crate::gen::central::global; pub use crate::gen::classes::*; pub use crate::gen::utilities; pub use io::*; -pub use script_instance::{create_script_instance, ScriptInstance}; +pub use script_instance::{create_script_instance, ScriptInstance, SiMut}; use crate::builtin::meta::CallContext; use crate::sys; diff --git a/godot-core/src/engine/script_instance.rs b/godot-core/src/engine/script_instance.rs index 7369babff..9cc42c8e5 100644 --- a/godot-core/src/engine/script_instance.rs +++ b/godot-core/src/engine/script_instance.rs @@ -5,14 +5,17 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -use std::cell::RefCell; use std::collections::HashMap; use std::ffi::c_void; +use std::ops::{Deref, DerefMut}; +use std::pin::Pin; use std::sync::Mutex; +use godot_cell::{GdCell, MutGuard}; + use crate::builtin::meta::{MethodInfo, PropertyInfo}; use crate::builtin::{GString, StringName, Variant, VariantType}; -use crate::obj::Gd; +use crate::obj::{Base, Gd, GodotClass, ScriptBaseMut, ScriptBaseRef}; use crate::sys; use super::{Script, ScriptLanguage}; @@ -65,14 +68,16 @@ use super::{Script, ScriptLanguage}; /// } /// } /// ``` -pub trait ScriptInstance { +pub trait ScriptInstance: Sized { + type Base: GodotClass; + /// Name of the new class the script implements. fn class_name(&self) -> GString; /// Property setter for Godot's virtual dispatch system. /// /// The engine will call this function when it wants to change a property on the script. - fn set_property(&mut self, name: StringName, value: &Variant) -> bool; + fn set_property(this: SiMut, name: StringName, value: &Variant) -> bool; /// Property getter for Godot's virtual dispatch system. /// @@ -93,7 +98,7 @@ pub trait ScriptInstance { /// It's important that the script does not cause a second call to this function while executing a method call. This would result in a panic. // TODO: map the sys::GDExtensionCallErrorType to some public API type. fn call( - &mut self, + this: SiMut, method: StringName, args: &[&Variant], ) -> Result; @@ -136,81 +141,7 @@ pub trait ScriptInstance { fn property_get_fallback(&self, name: StringName) -> Option; /// The engine may call this function if ScriptLanguage::is_placeholder_fallback_enabled is enabled. - fn property_set_fallback(&mut self, name: StringName, value: &Variant) -> bool; -} - -impl ScriptInstance for Box { - fn class_name(&self) -> GString { - self.as_ref().class_name() - } - - fn set_property(&mut self, name: StringName, value: &Variant) -> bool { - self.as_mut().set_property(name, value) - } - - fn get_property(&self, name: StringName) -> Option { - self.as_ref().get_property(name) - } - - fn get_property_list(&self) -> Vec { - self.as_ref().get_property_list() - } - - fn get_method_list(&self) -> Vec { - self.as_ref().get_method_list() - } - - fn call( - &mut self, - method: StringName, - args: &[&Variant], - ) -> Result { - self.as_mut().call(method, args) - } - - fn is_placeholder(&self) -> bool { - self.as_ref().is_placeholder() - } - - fn has_method(&self, method: StringName) -> bool { - self.as_ref().has_method(method) - } - - fn get_script(&self) -> &Gd