Skip to content

Commit 784fc7b

Browse files
authored
Merge pull request #168 from tom-leys/master
ClassDB - Restore missing _ from class names.
2 parents ca9649d + baa0703 commit 784fc7b

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

bindings_generator/src/api.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
use std::collections::HashMap;
1+
use std::collections::{HashMap, HashSet};
22
use serde_json;
33

44
pub struct Api {
55
pub classes: Vec<GodotClass>,
6+
pub api_underscore: HashSet<String>,
67
}
78

89
impl Api {
910
pub fn new() -> Self {
1011
let mut api = Api {
1112
classes: serde_json::from_slice(get_api_json()).expect("Failed to parse the API description"),
13+
api_underscore: Default::default(),
1214
};
1315

1416
api.strip_leading_underscores();
@@ -42,6 +44,7 @@ impl Api {
4244
for class in &mut self.classes {
4345
if class.name.starts_with('_') {
4446
class.name = class.name[1..].to_string();
47+
self.api_underscore.insert(class.name.clone());
4548
}
4649
for method in &mut class.methods {
4750
if method.return_type.starts_with('_') {

bindings_generator/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ fn generate_class_bindings(
167167

168168
// methods and method table
169169
{
170-
generate_method_table(output_method_table, class)?;
170+
let has_underscore = api.api_underscore.contains(&class.name);
171+
generate_method_table(output_method_table, class, has_underscore)?;
171172

172173
for method in &class.methods {
173174
generate_method_impl(output_method_table, class, method)?;

bindings_generator/src/methods.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn skip_method(name: &str) -> bool {
1111
name == "free" || name == "reference" || name == "unreference"
1212
}
1313

14-
pub fn generate_method_table(output: &mut impl Write, class: &GodotClass) -> GeneratorResult {
14+
pub fn generate_method_table(output: &mut impl Write, class: &GodotClass, has_underscore:bool) -> GeneratorResult {
1515
writeln!(output, r#"
1616
#[doc(hidden)]
1717
#[allow(non_camel_case_types)]
@@ -46,6 +46,11 @@ impl {name}MethodTable {{
4646
method.get_name()
4747
)?;
4848
}
49+
let lookup_name : String = if has_underscore {
50+
format!("_{class}", class= class.name)
51+
} else {
52+
class.name.clone()
53+
};
4954
writeln!(output, r#"
5055
}};
5156
@@ -71,9 +76,10 @@ impl {name}MethodTable {{
7176
#[inline(never)]
7277
fn init(table: &mut Self, gd_api: &GodotApi) {{
7378
unsafe {{
74-
let class_name = b"{name}\0".as_ptr() as *const c_char;
79+
let class_name = b"{lookup_name}\0".as_ptr() as *const c_char;
7580
table.class_constructor = (gd_api.godot_get_class_constructor)(class_name);"#,
76-
name = class.name
81+
name = class.name,
82+
lookup_name = lookup_name,
7783
)?;
7884
for method in &class.methods {
7985
let method_name = method.get_name();

0 commit comments

Comments
 (0)