This repository was archived by the owner on Dec 31, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- use std:: collections:: HashMap ;
1+ use std:: collections:: { HashMap , HashSet } ;
22use serde_json;
33
44pub struct Api {
55 pub classes : Vec < GodotClass > ,
6+ pub api_underscore : HashSet < String > ,
67}
78
89impl 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 ( '_' ) {
Original file line number Diff line number Diff 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) ?;
Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments