Skip to content

Commit

Permalink
Implementation of godots GDExtensionScriptInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Nov 21, 2023
1 parent 13ab375 commit 8ca5b52
Show file tree
Hide file tree
Showing 4 changed files with 532 additions and 0 deletions.
2 changes: 2 additions & 0 deletions godot-codegen/src/codegen_special_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ const SELECTED_CLASSES: &[&str] = &[
"ResourceLoader",
"RigidBody2D",
"SceneTree",
"Script",
"ScriptLanguage",
"Sprite2D",
"SpriteFrames",
"TextServer",
Expand Down
48 changes: 48 additions & 0 deletions godot-core/src/builtin/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,51 @@ impl PropertyInfo {
}
}
}

#[derive(Debug)]
pub struct MethodInfo {
pub id: i32,
pub method_name: StringName,
pub class_name: ClassName,
pub return_type: PropertyInfo,
pub arguments: Vec<PropertyInfo>,
pub default_arguments: Vec<Variant>,
pub flags: global::MethodFlags,
}

impl MethodInfo {
pub fn method_sys(&self) -> sys::GDExtensionMethodInfo {
use crate::obj::EngineEnum as _;

let argument_count = self.arguments.len() as u32;
let argument_vec = self
.arguments
.iter()
.map(|arg| arg.property_sys())
.collect::<Vec<_>>()
.into_boxed_slice();

let arguments = unsafe { (*Box::into_raw(argument_vec)).as_mut_ptr() };

let default_argument_count = self.default_arguments.len() as u32;
let default_argument_vec = self
.default_arguments
.iter()
.map(|arg| arg.var_sys())
.collect::<Vec<_>>()
.into_boxed_slice();

let default_arguments = unsafe { (*Box::into_raw(default_argument_vec)).as_mut_ptr() };

sys::GDExtensionMethodInfo {
id: self.id,
name: self.method_name.string_sys(),
return_value: self.return_type.property_sys(),
argument_count,
arguments,
default_argument_count,
default_arguments,
flags: u32::try_from(self.flags.ord()).expect("flags should be valid"),
}
}
}
2 changes: 2 additions & 0 deletions godot-core/src/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub use real_inner::*;
pub use rect2::*;
pub use rect2i::*;
pub use rid::*;
pub use script::*;
pub use string::*;
pub use transform2d::*;
pub use transform3d::*;
Expand Down Expand Up @@ -91,6 +92,7 @@ mod quaternion;
mod rect2;
mod rect2i;
mod rid;
mod script;
mod string;
mod transform2d;
mod transform3d;
Expand Down
Loading

0 comments on commit 8ca5b52

Please sign in to comment.