Skip to content

Commit 947486b

Browse files
authored
Rip out abi_stable (#29)
1 parent 7620ce6 commit 947486b

File tree

15 files changed

+246
-861
lines changed

15 files changed

+246
-861
lines changed

Cargo.lock

Lines changed: 4 additions & 324 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ edition = "2021"
1212
[workspace.dependencies]
1313
godot = { git = "https://github.com/titannano/gdext", rev = "7fd1be904efccd71a9eb980c2e6fffa2d8705ec4" }
1414
itertools = "0.10.3"
15-
abi_stable = { version = "0.11.2", default-features = false }
1615
rand = "0.8.5"
1716
darling = { version = "0.20.3" }
1817
proc-macro2 = "1.0.68"

derive/src/impl_attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn godot_script_impl(
117117
fnc.span() =>
118118
::godot_rust_script::RustScriptMethodDesc {
119119
name: #fn_name_str,
120-
arguments: vec![#args_meta],
120+
arguments: Box::new([#args_meta]),
121121
return_type: ::godot_rust_script::RustScriptPropDesc {
122122
name: #fn_name_str,
123123
ty: #fn_return_ty,

rust-script/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition.workspace = true
77

88
[dependencies]
99
godot.workspace = true
10-
abi_stable.workspace = true
1110

1211
itertools = { workspace = true, optional = true }
1312
rand = { workspace = true, optional = true }

rust-script/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ pub use runtime::*;
2222
pub use godot_rust_script_derive::{godot_script_impl, GodotScript};
2323

2424
pub mod private_export {
25-
pub use super::script_registry::RemoteVariantType;
2625
pub use super::shared::__godot_rust_plugin_SCRIPT_REGISTRY;
27-
pub use abi_stable::std_types::{RStr, RString, RVec};
2826
pub use const_str::{concat, replace, strip_prefix, unwrap};
2927
pub use godot::sys::{plugin_add, plugin_registry};
3028
}

rust-script/src/library.rs

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,18 @@
66

77
use std::collections::BTreeMap;
88

9-
use abi_stable::{
10-
sabi_trait::TD_Opaque,
11-
std_types::{RBox, RStr, RString, RVec},
12-
};
139
use godot::{
1410
engine::global::{MethodFlags, PropertyHint, PropertyUsageFlags},
1511
obj::{EngineBitfield, EngineEnum},
1612
prelude::{Gd, Object},
1713
sys::VariantType,
1814
};
1915

20-
pub use crate::script_registry::{
21-
GodotScript, GodotScriptImpl, RemoteScriptMetaData, RemoteScriptMethodInfo,
16+
use crate::script_registry::{
17+
CreateScriptInstanceData, GodotScriptObject, RustScriptPropertyInfo, RustScriptSignalInfo,
2218
};
23-
use crate::{
24-
apply::Apply,
25-
script_registry::{RemoteGodotScript_TO, RemoteScriptPropertyInfo, RemoteScriptSignalInfo},
19+
pub use crate::script_registry::{
20+
GodotScript, GodotScriptImpl, RustScriptMetaData, RustScriptMethodInfo,
2621
};
2722
pub use signals::{ScriptSignal, Signal, SignalArguments};
2823

@@ -68,8 +63,7 @@ macro_rules! register_script_methods {
6863
macro_rules! setup_library {
6964
() => {
7065
#[no_mangle]
71-
pub fn __godot_rust_script_init(
72-
) -> $crate::private_export::RVec<$crate::RemoteScriptMetaData> {
66+
pub fn __godot_rust_script_init() -> ::std::vec::Vec<$crate::RustScriptMetaData> {
7367
use $crate::godot::obj::EngineEnum;
7468
use $crate::private_export::*;
7569

@@ -100,7 +94,7 @@ pub struct RustScriptEntry {
10094
pub base_type_name: &'static str,
10195
pub properties: fn() -> Vec<RustScriptPropDesc>,
10296
pub signals: fn() -> Vec<RustScriptSignalDesc>,
103-
pub create_data: fn(Gd<Object>) -> RemoteGodotScript_TO<'static, RBox<()>>,
97+
pub create_data: fn(Gd<Object>) -> Box<dyn GodotScriptObject>,
10498
pub description: &'static str,
10599
}
106100

@@ -126,78 +120,78 @@ pub struct RustScriptPropDesc {
126120
}
127121

128122
impl RustScriptPropDesc {
129-
pub fn into_property_info(self, class_name: &'static str) -> RemoteScriptPropertyInfo {
130-
RemoteScriptPropertyInfo {
131-
variant_type: self.ty.into(),
132-
class_name: RStr::from_str(class_name),
133-
property_name: RString::with_capacity(self.name.len()).apply(|s| s.push_str(self.name)),
123+
pub fn to_property_info(&self, class_name: &'static str) -> RustScriptPropertyInfo {
124+
RustScriptPropertyInfo {
125+
variant_type: self.ty,
126+
class_name,
127+
property_name: self.name,
134128
usage: if self.exported {
135129
(PropertyUsageFlags::EDITOR | PropertyUsageFlags::STORAGE).ord()
136130
} else {
137131
PropertyUsageFlags::NONE.ord()
138132
},
139133
hint: self.hint.ord(),
140-
hint_string: self.hint_string.into(),
141-
description: RStr::from_str(self.description),
134+
hint_string: self.hint_string,
135+
description: self.description,
142136
}
143137
}
144138
}
145139

146140
pub struct RustScriptMethodDesc {
147141
pub name: &'static str,
148142
pub return_type: RustScriptPropDesc,
149-
pub arguments: Vec<RustScriptPropDesc>,
143+
pub arguments: Box<[RustScriptPropDesc]>,
150144
pub flags: MethodFlags,
151145
pub description: &'static str,
152146
}
153147

154148
impl RustScriptMethodDesc {
155-
pub fn into_method_info(self, id: i32, class_name: &'static str) -> RemoteScriptMethodInfo {
156-
RemoteScriptMethodInfo {
149+
pub fn to_method_info(self, id: i32, class_name: &'static str) -> RustScriptMethodInfo {
150+
RustScriptMethodInfo {
157151
id,
158-
method_name: self.name.into(),
159-
class_name: class_name.into(),
160-
return_type: self.return_type.into_property_info(class_name),
152+
method_name: self.name,
153+
class_name,
154+
return_type: self.return_type.to_property_info(class_name),
161155
flags: self.flags.ord(),
162156
arguments: self
163157
.arguments
164-
.into_iter()
165-
.map(|arg| arg.into_property_info(class_name))
158+
.iter()
159+
.map(|arg| arg.to_property_info(class_name))
166160
.collect(),
167-
description: RStr::from_str(self.description),
161+
description: self.description,
168162
}
169163
}
170164
}
171165

172166
pub struct RustScriptSignalDesc {
173167
pub name: &'static str,
174-
pub arguments: Vec<RustScriptPropDesc>,
168+
pub arguments: Box<[RustScriptPropDesc]>,
175169
pub description: &'static str,
176170
}
177171

178-
impl From<RustScriptSignalDesc> for RemoteScriptSignalInfo {
172+
impl From<RustScriptSignalDesc> for RustScriptSignalInfo {
179173
fn from(value: RustScriptSignalDesc) -> Self {
180174
Self {
181-
name: value.name.into(),
175+
name: value.name,
182176
arguments: value
183177
.arguments
184-
.into_iter()
185-
.map(|arg| arg.into_property_info("\0"))
178+
.iter()
179+
.map(|arg| arg.to_property_info("\0"))
186180
.collect(),
187-
description: value.description.into(),
181+
description: value.description,
188182
}
189183
}
190184
}
191185

192-
pub fn create_default_data_struct<T: GodotScript + 'static>(
186+
pub fn create_default_data_struct<T: GodotScript + GodotScriptObject + 'static>(
193187
base: Gd<Object>,
194-
) -> RemoteGodotScript_TO<'static, RBox<()>> {
195-
RemoteGodotScript_TO::from_value(T::default_with_base(base), TD_Opaque)
188+
) -> Box<dyn GodotScriptObject> {
189+
Box::new(T::default_with_base(base))
196190
}
197191

198192
pub fn assemble_metadata<'a>(
199193
items: impl Iterator<Item = &'a RegistryItem> + 'a,
200-
) -> RVec<RemoteScriptMetaData> {
194+
) -> Vec<RustScriptMetaData> {
201195
let (entries, methods): (Vec<_>, Vec<_>) = items
202196
.map(|item| match item {
203197
RegistryItem::Entry(entry) => (Some(entry), None),
@@ -213,32 +207,30 @@ pub fn assemble_metadata<'a>(
213207
.map(|class| {
214208
let props = (class.properties)()
215209
.into_iter()
216-
.map(|prop| prop.into_property_info(class.class_name))
210+
.map(|prop| prop.to_property_info(class.class_name))
217211
.collect();
218212

219213
let methods = methods
220214
.get(class.class_name)
221215
.into_iter()
222216
.flat_map(|entry| (entry.methods)())
223217
.enumerate()
224-
.map(|(index, method)| {
225-
method.into_method_info((index + 1) as i32, class.class_name)
226-
})
218+
.map(|(index, method)| method.to_method_info((index + 1) as i32, class.class_name))
227219
.collect();
228220

229221
let signals = (class.signals)().into_iter().map(Into::into).collect();
230222

231-
let create_data = class.create_data;
223+
let create_data: Box<dyn CreateScriptInstanceData> = Box::new(class.create_data);
232224
let description = class.description;
233225

234-
RemoteScriptMetaData::new(
235-
class.class_name.into(),
226+
RustScriptMetaData::new(
227+
class.class_name,
236228
class.base_type_name.into(),
237229
props,
238230
methods,
239231
signals,
240232
create_data,
241-
description.into(),
233+
description,
242234
)
243235
})
244236
.collect()

rust-script/src/library/signals.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub trait ScriptSignal {
2828

2929
fn connect(&mut self, callable: Callable) -> Result<(), Error>;
3030

31-
fn argument_desc() -> Vec<RustScriptPropDesc>;
31+
fn argument_desc() -> Box<[RustScriptPropDesc]>;
3232

3333
fn name(&self) -> &str;
3434
}
@@ -38,7 +38,7 @@ pub trait SignalArguments {
3838

3939
fn to_variants(&self) -> Vec<Variant>;
4040

41-
fn argument_desc() -> Vec<RustScriptPropDesc>;
41+
fn argument_desc() -> Box<[RustScriptPropDesc]>;
4242
}
4343

4444
impl SignalArguments for () {
@@ -50,8 +50,8 @@ impl SignalArguments for () {
5050
vec![]
5151
}
5252

53-
fn argument_desc() -> Vec<RustScriptPropDesc> {
54-
vec![]
53+
fn argument_desc() -> Box<[RustScriptPropDesc]> {
54+
Box::new([])
5555
}
5656
}
5757

@@ -76,10 +76,10 @@ macro_rules! tuple_args {
7676
]
7777
}
7878

79-
fn argument_desc() -> Vec<RustScriptPropDesc> {
80-
vec![
79+
fn argument_desc() -> Box<[RustScriptPropDesc]> {
80+
Box::new([
8181
$(signal_argument_desc!("0", $arg)),+
82-
]
82+
])
8383
}
8484
}
8585
};
@@ -109,10 +109,10 @@ macro_rules! single_args {
109109
vec![self.to_variant()]
110110
}
111111

112-
fn argument_desc() -> Vec<RustScriptPropDesc> {
113-
vec![
112+
fn argument_desc() -> Box<[RustScriptPropDesc]> {
113+
Box::new([
114114
signal_argument_desc!("0", $arg),
115-
]
115+
])
116116
}
117117
}
118118
};
@@ -172,7 +172,7 @@ impl<T: SignalArguments> ScriptSignal for Signal<T> {
172172
}
173173
}
174174

175-
fn argument_desc() -> Vec<RustScriptPropDesc> {
175+
fn argument_desc() -> Box<[RustScriptPropDesc]> {
176176
<T as SignalArguments>::argument_desc()
177177
}
178178

0 commit comments

Comments
 (0)