File tree 3 files changed +15
-5
lines changed 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change 1
- use std:: collections:: HashMap ;
1
+ use std:: collections:: { HashMap , HashSet } ;
2
2
use serde_json;
3
3
4
4
pub struct Api {
5
5
pub classes : Vec < GodotClass > ,
6
+ pub api_underscore : HashSet < String > ,
6
7
}
7
8
8
9
impl Api {
9
10
pub fn new ( ) -> Self {
10
11
let mut api = Api {
11
12
classes : serde_json:: from_slice ( get_api_json ( ) ) . expect ( "Failed to parse the API description" ) ,
13
+ api_underscore : Default :: default ( ) ,
12
14
} ;
13
15
14
16
api. strip_leading_underscores ( ) ;
@@ -42,6 +44,7 @@ impl Api {
42
44
for class in & mut self . classes {
43
45
if class. name . starts_with ( '_' ) {
44
46
class. name = class. name [ 1 ..] . to_string ( ) ;
47
+ self . api_underscore . insert ( class. name . clone ( ) ) ;
45
48
}
46
49
for method in & mut class. methods {
47
50
if method. return_type . starts_with ( '_' ) {
Original file line number Diff line number Diff line change @@ -167,7 +167,8 @@ fn generate_class_bindings(
167
167
168
168
// methods and method table
169
169
{
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) ?;
171
172
172
173
for method in & class. methods {
173
174
generate_method_impl ( output_method_table, class, method) ?;
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ fn skip_method(name: &str) -> bool {
11
11
name == "free" || name == "reference" || name == "unreference"
12
12
}
13
13
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 {
15
15
writeln ! ( output, r#"
16
16
#[doc(hidden)]
17
17
#[allow(non_camel_case_types)]
@@ -46,6 +46,11 @@ impl {name}MethodTable {{
46
46
method. get_name( )
47
47
) ?;
48
48
}
49
+ let lookup_name : String = if has_underscore {
50
+ format ! ( "_{class}" , class= class. name)
51
+ } else {
52
+ class. name . clone ( )
53
+ } ;
49
54
writeln ! ( output, r#"
50
55
}};
51
56
@@ -71,9 +76,10 @@ impl {name}MethodTable {{
71
76
#[inline(never)]
72
77
fn init(table: &mut Self, gd_api: &GodotApi) {{
73
78
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;
75
80
table.class_constructor = (gd_api.godot_get_class_constructor)(class_name);"# ,
76
- name = class. name
81
+ name = class. name,
82
+ lookup_name = lookup_name,
77
83
) ?;
78
84
for method in & class. methods {
79
85
let method_name = method. get_name ( ) ;
You can’t perform that action at this time.
0 commit comments