Skip to content

Commit b51093b

Browse files
ecobiubiuBromeon
authored andcommitted
Print properties in both Rust and GDScript, to highlight ordering discrepancies
1 parent 7dffc38 commit b51093b

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
extends Node
2+
3+
func _ready():
4+
var rust = get_node("../PropertyExport")
5+
6+
print("\n-----------------------------------------------------------------")
7+
print("Print from GDScript (note the deterministically ordered map/set):")
8+
print(" Vec (name):");
9+
for name in rust.name_vec:
10+
print(" * %s" % name)
11+
12+
print("\n HashMap (string -> color):")
13+
for string in rust.color_map:
14+
var color = rust.color_map[string]
15+
print(" * %s -> #%s" % [string, color.to_html(false)]);
16+
17+
print("\n HashSet (ID):")
18+
for id in rust.id_set:
19+
print(" * %s" % id)
20+
21+
# The program has printed the contents and fulfilled its purpose, quit
22+
get_tree().quit()

examples/property-export/Main.tscn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
[gd_scene load_steps=3 format=2]
1+
[gd_scene load_steps=4 format=2]
22

33
[ext_resource path="res://property_export_library.gdnlib" type="GDNativeLibrary" id=1]
4+
[ext_resource path="res://GDScriptPrinter.gd" type="Script" id=2]
45

56
[sub_resource type="NativeScript" id=1]
67
resource_name = "PropertyExport"
@@ -18,3 +19,6 @@ color_map = {
1819
"teal": Color( 0.0941176, 0.423529, 0.564706, 1 )
1920
}
2021
id_set = [ 21, 77, 8, 90 ]
22+
23+
[node name="GDScriptPrinter" type="Node" parent="."]
24+
script = ExtResource( 2 )

examples/property-export/src/lib.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,23 @@ impl PropertyExport {
2222
}
2323

2424
#[export]
25-
fn _ready(&self, base: &Node) {
26-
godot_print!("Vec (name):");
25+
fn _ready(&self, _base: &Node) {
26+
godot_print!("------------------------------------------------------------------");
27+
godot_print!("Print from Rust (note the unordered map/set):");
28+
godot_print!(" Vec (name):");
2729
for name in &self.name_vec {
28-
godot_print!("* {}", name);
30+
godot_print!(" * {}", name);
2931
}
3032

31-
godot_print!("\nHashMap (string -> color):");
33+
godot_print!("\n HashMap (string -> color):");
3234
for (string, color) in &self.color_map {
33-
godot_print!("* {} -> #{}", string, color.to_html(false));
35+
godot_print!(" * {} -> #{}", string, color.to_html(false));
3436
}
3537

36-
godot_print!("\nHashSet (ID):");
38+
godot_print!("\n HashSet (ID):");
3739
for id in &self.id_set {
38-
godot_print!("* {}", id);
40+
godot_print!(" * {}", id);
3941
}
40-
41-
// The program has printed the contents and fulfilled its purpose, quit
42-
let scene_tree = base.get_tree().unwrap();
43-
unsafe { scene_tree.assume_safe() }.quit(0);
4442
}
4543
}
4644

0 commit comments

Comments
 (0)