Skip to content

Commit 32c0f62

Browse files
authored
Update to latest gdext (#13)
1 parent c5c697c commit 32c0f62

File tree

8 files changed

+88
-89
lines changed

8 files changed

+88
-89
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ version = "0.1.0"
1010
edition = "2021"
1111

1212
[workspace.dependencies]
13-
godot = { git = "https://github.com/titannano/gdext", rev = "0f9a3e22f9cbdc31e0c575a12c69d26241a92f9f" }
13+
godot = { git = "https://github.com/titannano/gdext", rev = "a5d17342b7b47e8af652a6a733f497c468bbd59a" }
1414
hot-lib-reloader = "0.6.5"
1515
itertools = "0.10.3"
1616
abi_stable = { version = "0.11.2", default-features = false }
@@ -23,4 +23,4 @@ syn = "2.0.38"
2323
process_path = "0.1"
2424

2525
godot-rust-script-derive = { path = "derive" }
26-
tests-scripts-lib = { path = "tests-scripts-lib" }
26+
tests-scripts-lib = { path = "tests-scripts-lib" }

rust-script/src/runtime/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ impl RustScriptExtensionLayer {
139139

140140
let lang: Gd<RustScriptLanguage> = RustScriptLanguage::new(self.scripts_src_dir);
141141
let res_loader = RustScriptResourceLoader::new(lang.clone());
142-
let res_saver = Gd::new(RustScriptResourceSaver);
142+
let res_saver = Gd::from_object(RustScriptResourceSaver);
143143

144144
cfg_if! {
145145
if #[cfg(all(feature = "hot-reload", debug_assertions))] {
146146
use godot::prelude::StringName;
147147

148-
let mut hot_reloader = Gd::with_base(|base| HotReloader::new((self.hot_reload_subscribe)(), self.lib_init_fn.clone(), base));
148+
let mut hot_reloader = Gd::from_init_fn(|base| HotReloader::new((self.hot_reload_subscribe)(), self.lib_init_fn.clone(), base));
149149

150150
hot_reloader.call_deferred(StringName::from("register"), &[]);
151151

rust-script/src/runtime/resource_loader.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use godot::{
2-
engine::{
3-
file_access, FileAccess, ResourceFormatLoaderVirtual, Script,
4-
ScriptLanguageExtensionVirtual,
5-
},
2+
engine::{file_access, FileAccess, IResourceFormatLoader, IScriptLanguageExtension, Script},
63
prelude::{
7-
godot_api, Gd, GodotClass, GodotString, PackedStringArray, StringName, ToGodot, Variant,
4+
godot_api, GString, Gd, GodotClass, PackedStringArray, StringName, ToGodot, Variant,
85
},
96
};
107

@@ -18,23 +15,24 @@ pub(super) struct RustScriptResourceLoader {
1815

1916
impl RustScriptResourceLoader {
2017
pub fn new(script_lang: Gd<RustScriptLanguage>) -> Gd<Self> {
21-
Gd::new(Self { script_lang })
18+
Gd::from_object(Self { script_lang })
2219
}
2320
}
2421

2522
#[godot_api]
26-
impl ResourceFormatLoaderVirtual for RustScriptResourceLoader {
23+
impl IResourceFormatLoader for RustScriptResourceLoader {
2724
fn handles_type(&self, type_: StringName) -> bool {
2825
type_ == StringName::from("Script") || type_ == self.script_lang.bind().get_type().into()
2926
}
30-
fn get_resource_type(&self, path: GodotString) -> GodotString {
27+
28+
fn get_resource_type(&self, path: GString) -> GString {
3129
let script_lang = self.script_lang.bind();
3230
let ext_match = path
3331
.to_string()
3432
.ends_with(&script_lang.get_extension().to_string());
3533

3634
if !ext_match {
37-
return GodotString::new();
35+
return GString::new();
3836
}
3937

4038
script_lang.get_type()
@@ -46,8 +44,8 @@ impl ResourceFormatLoaderVirtual for RustScriptResourceLoader {
4644

4745
fn load(
4846
&self,
49-
path: GodotString,
50-
original_path: GodotString,
47+
path: GString,
48+
original_path: GString,
5149
_use_sub_threads: bool,
5250
_cache_mode: i32,
5351
) -> Variant {

rust-script/src/runtime/resource_saver.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use godot::{
22
engine::{
3-
file_access, global, resource_saver::SaverFlags, FileAccess, ResourceFormatSaverVirtual,
4-
Script,
3+
file_access, global, resource_saver::SaverFlags, FileAccess, IResourceFormatSaver, Script,
54
},
65
obj::EngineEnum,
7-
prelude::{godot_api, godot_print, Gd, GodotClass, GodotString, PackedStringArray, Resource},
6+
prelude::{godot_api, godot_print, GString, Gd, GodotClass, PackedStringArray, Resource},
87
};
98

109
use super::rust_script::RustScript;
@@ -14,8 +13,8 @@ use super::rust_script::RustScript;
1413
pub struct RustScriptResourceSaver;
1514

1615
#[godot_api]
17-
impl ResourceFormatSaverVirtual for RustScriptResourceSaver {
18-
fn save(&mut self, resource: Gd<Resource>, path: GodotString, flags: u32) -> global::Error {
16+
impl IResourceFormatSaver for RustScriptResourceSaver {
17+
fn save(&mut self, resource: Gd<Resource>, path: GString, flags: u32) -> global::Error {
1918
let mut script: Gd<Script> = resource.cast();
2019

2120
godot_print!("saving rust script resource to: {}", path);
@@ -42,9 +41,9 @@ impl ResourceFormatSaverVirtual for RustScriptResourceSaver {
4241
resource.try_cast::<RustScript>().is_some()
4342
}
4443
fn get_recognized_extensions(&self, _resource: Gd<Resource>) -> PackedStringArray {
45-
PackedStringArray::from(&[GodotString::from("rs")])
44+
PackedStringArray::from(&[GString::from("rs")])
4645
}
47-
fn recognize_path(&self, _resource: Gd<Resource>, _path: GodotString) -> bool {
46+
fn recognize_path(&self, _resource: Gd<Resource>, _path: GString) -> bool {
4847
true
4948
}
5049
}

rust-script/src/runtime/rust_script.rs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use std::{ffi::c_void, ops::Deref};
33
use abi_stable::std_types::RBox;
44
use godot::{
55
builtin::create_script_instance,
6-
engine::{Engine, Script, ScriptExtension, ScriptExtensionVirtual, ScriptLanguage},
6+
engine::{Engine, IScriptExtension, Script, ScriptExtension, ScriptLanguage},
7+
obj::UserClass,
78
prelude::{
8-
godot_api, Array, Base, Dictionary, Gd, GodotClass, GodotString, Object, StringName,
9+
godot_api, Array, Base, Dictionary, GString, Gd, GodotClass, Object, StringName,
910
VariantArray,
1011
},
1112
};
@@ -30,14 +31,14 @@ pub(super) struct RustScript {
3031

3132
impl RustScript {
3233
pub fn new(class_name: String) -> Gd<Self> {
33-
Gd::with_base(|base| Self {
34+
Gd::from_init_fn(|base| Self {
3435
class_name,
3536
source_code: String::new(),
3637
base,
3738
})
3839
}
3940

40-
pub fn class_name(&self) -> GodotString {
41+
pub fn class_name(&self) -> GString {
4142
self.class_name.clone().into()
4243
}
4344

@@ -61,7 +62,7 @@ impl RustScript {
6162
}
6263

6364
#[godot_api]
64-
impl ScriptExtensionVirtual for RustScript {
65+
impl IScriptExtension for RustScript {
6566
fn init(base: Base<Self::Base>) -> Self {
6667
Self {
6768
class_name: String::new(),
@@ -70,15 +71,15 @@ impl ScriptExtensionVirtual for RustScript {
7071
}
7172
}
7273

73-
fn get_source_code(&self) -> GodotString {
74+
fn get_source_code(&self) -> GString {
7475
self.source_code.clone().into()
7576
}
76-
fn set_source_code(&mut self, code: GodotString) {
77+
fn set_source_code(&mut self, code: GString) {
7778
self.source_code = code.to_string();
7879
}
7980

8081
fn get_language(&self) -> Option<Gd<ScriptLanguage>> {
81-
Some(Gd::<RustScriptLanguage>::new_default().upcast())
82+
Some(RustScriptLanguage::alloc_gd().upcast())
8283
}
8384

8485
fn can_instantiate(&self) -> bool {
@@ -223,24 +224,24 @@ impl ScriptExtensionVirtual for RustScript {
223224
.unwrap_or_default();
224225

225226
let class_doc = Dictionary::new().apply(|dict| {
226-
dict.set(GodotString::from("name"), self.class_name());
227-
dict.set(GodotString::from("inherits"), self.get_instance_base_type());
228-
dict.set(GodotString::from("brief_description"), GodotString::new());
229-
dict.set(GodotString::from("description"), description);
230-
dict.set(GodotString::from("tutorials"), VariantArray::new());
231-
dict.set(GodotString::from("constructors"), VariantArray::new());
232-
dict.set(GodotString::from("methods"), methods);
233-
dict.set(GodotString::from("operators"), VariantArray::new());
234-
dict.set(GodotString::from("signals"), VariantArray::new());
235-
dict.set(GodotString::from("constants"), VariantArray::new());
236-
dict.set(GodotString::from("enums"), VariantArray::new());
237-
dict.set(GodotString::from("properties"), props);
238-
dict.set(GodotString::from("theme_properties"), VariantArray::new());
239-
dict.set(GodotString::from("annotations"), VariantArray::new());
240-
dict.set(GodotString::from("is_deprecated"), false);
241-
dict.set(GodotString::from("is_experimental"), false);
242-
dict.set(GodotString::from("is_script_doc"), true);
243-
dict.set(GodotString::from("script_path"), self.base.get_path());
227+
dict.set(GString::from("name"), self.class_name());
228+
dict.set(GString::from("inherits"), self.get_instance_base_type());
229+
dict.set(GString::from("brief_description"), GString::new());
230+
dict.set(GString::from("description"), description);
231+
dict.set(GString::from("tutorials"), VariantArray::new());
232+
dict.set(GString::from("constructors"), VariantArray::new());
233+
dict.set(GString::from("methods"), methods);
234+
dict.set(GString::from("operators"), VariantArray::new());
235+
dict.set(GString::from("signals"), VariantArray::new());
236+
dict.set(GString::from("constants"), VariantArray::new());
237+
dict.set(GString::from("enums"), VariantArray::new());
238+
dict.set(GString::from("properties"), props);
239+
dict.set(GString::from("theme_properties"), VariantArray::new());
240+
dict.set(GString::from("annotations"), VariantArray::new());
241+
dict.set(GString::from("is_deprecated"), false);
242+
dict.set(GString::from("is_experimental"), false);
243+
dict.set(GString::from("is_script_doc"), true);
244+
dict.set(GString::from("script_path"), self.base.get_path());
244245
});
245246

246247
Array::from(&[class_doc])

rust-script/src/runtime/rust_script_instance.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ use cfg_if::cfg_if;
1111
use godot::{
1212
builtin::ScriptInstance,
1313
engine::Script,
14+
obj::UserClass,
1415
prelude::{
1516
godot_print,
1617
meta::{MethodInfo, PropertyInfo},
17-
Gd, GodotString, Object, StringName, Variant, VariantType,
18+
GString, Gd, Object, StringName, Variant, VariantType,
1819
},
1920
};
2021

@@ -44,7 +45,7 @@ fn script_method_list(script: &Gd<RustScript>) -> Rc<Vec<MethodInfo>> {
4445
})
4546
}
4647

47-
fn script_class_name(script: &Gd<RustScript>) -> GodotString {
48+
fn script_class_name(script: &Gd<RustScript>) -> GString {
4849
script.bind().class_name()
4950
}
5051

@@ -170,7 +171,7 @@ cfg_if! {
170171
}
171172

172173
impl ScriptInstance for RustScriptInstance {
173-
fn class_name(&self) -> GodotString {
174+
fn class_name(&self) -> GString {
174175
script_class_name(&self.script)
175176
}
176177

@@ -247,7 +248,7 @@ impl ScriptInstance for RustScriptInstance {
247248
.unwrap_or(godot::sys::VariantType::Nil)
248249
}
249250

250-
fn to_string(&self) -> GodotString {
251+
fn to_string(&self) -> GString {
251252
self.with_data(|data| data.to_string()).into_string().into()
252253
}
253254

@@ -268,7 +269,7 @@ impl ScriptInstance for RustScriptInstance {
268269
}
269270

270271
fn language(&self) -> Gd<godot::engine::ScriptLanguage> {
271-
Gd::<RustScriptLanguage>::new_default().upcast()
272+
RustScriptLanguage::alloc_gd().upcast()
272273
}
273274

274275
fn refcount_decremented(&self) -> bool {
@@ -293,7 +294,7 @@ impl RustScriptPlaceholder {
293294
}
294295

295296
impl ScriptInstance for RustScriptPlaceholder {
296-
fn class_name(&self) -> GodotString {
297+
fn class_name(&self) -> GString {
297298
script_class_name(&self.script)
298299
}
299300

@@ -353,8 +354,8 @@ impl ScriptInstance for RustScriptPlaceholder {
353354
.unwrap_or(VariantType::Nil)
354355
}
355356

356-
fn to_string(&self) -> GodotString {
357-
GodotString::new()
357+
fn to_string(&self) -> GString {
358+
GString::new()
358359
}
359360

360361
fn owner(&self) -> Gd<godot::prelude::Object> {
@@ -369,7 +370,7 @@ impl ScriptInstance for RustScriptPlaceholder {
369370
}
370371

371372
fn language(&self) -> Gd<godot::engine::ScriptLanguage> {
372-
Gd::<RustScriptLanguage>::new_default().upcast()
373+
RustScriptLanguage::alloc_gd().upcast()
373374
}
374375

375376
fn refcount_decremented(&self) -> bool {

0 commit comments

Comments
 (0)