3
3
4
4
DIR = os .path .abspath ( os .path .dirname (__file__ ) )
5
5
OUTPUT_FILE = os .path .join (DIR , "quickjs_builtin_binder.gen.cpp" )
6
- API = json .load (open (os .path .join (DIR , '..' , 'buitin_api .gen.json' ), 'r' ))
6
+ API = json .load (open (os .path .join (DIR , '..' , 'builtin_api .gen.json' ), 'r' ))
7
7
8
8
VariantTypes = {
9
9
"boolean" : "Variant::BOOL" ,
104
104
"Variant" : 'QuickJSBinder::variant_to_var(ctx, ${arg})' ,
105
105
}
106
106
107
- def apply_parttern (template , values ):
107
+ def apply_pattern (template , values ):
108
108
for key in values :
109
109
template = template .replace ( '${' + key + '}' , values [key ])
110
110
return template
@@ -411,22 +411,22 @@ def generate_constructor(cls):
411
411
}
412
412
}
413
413
''' ,
414
- "PoolByteArray" : apply_parttern (TemplatePoolArrays , {"class" : "PoolByteArray" , "type" : "Variant::POOL_BYTE_ARRAY" , "element" : "uint8_t" }),
415
- "PoolIntArray" : apply_parttern (TemplatePoolArrays , {"class" : "PoolIntArray" , "type" : "Variant::POOL_INT_ARRAY" , "element" : "int" }),
416
- "PoolRealArray" : apply_parttern (TemplatePoolArrays , {"class" : "PoolRealArray" , "type" : "Variant::POOL_REAL_ARRAY" , "element" : "real_t" }),
417
- "PoolVector2Array" : apply_parttern (TemplatePoolArrays , {"class" : "PoolVector2Array" , "type" : "Variant::POOL_VECTOR2_ARRAY" , "element" : "Vector2" }),
418
- "PoolVector3Array" : apply_parttern (TemplatePoolArrays , {"class" : "PoolVector3Array" , "type" : "Variant::POOL_VECTOR3_ARRAY" , "element" : "Vector3" }),
419
- "PoolColorArray" : apply_parttern (TemplatePoolArrays , {"class" : "PoolColorArray" , "type" : "Variant::POOL_COLOR_ARRAY" , "element" : "Color" }),
420
- "PoolStringArray" : apply_parttern (TemplateSimplePoolArrays ,{"class" : "PoolStringArray" , "type" : "Variant::POOL_STRING_ARRAY" , "element" : "String" }),
414
+ "PoolByteArray" : apply_pattern (TemplatePoolArrays , {"class" : "PoolByteArray" , "type" : "Variant::POOL_BYTE_ARRAY" , "element" : "uint8_t" }),
415
+ "PoolIntArray" : apply_pattern (TemplatePoolArrays , {"class" : "PoolIntArray" , "type" : "Variant::POOL_INT_ARRAY" , "element" : "int" }),
416
+ "PoolRealArray" : apply_pattern (TemplatePoolArrays , {"class" : "PoolRealArray" , "type" : "Variant::POOL_REAL_ARRAY" , "element" : "real_t" }),
417
+ "PoolVector2Array" : apply_pattern (TemplatePoolArrays , {"class" : "PoolVector2Array" , "type" : "Variant::POOL_VECTOR2_ARRAY" , "element" : "Vector2" }),
418
+ "PoolVector3Array" : apply_pattern (TemplatePoolArrays , {"class" : "PoolVector3Array" , "type" : "Variant::POOL_VECTOR3_ARRAY" , "element" : "Vector3" }),
419
+ "PoolColorArray" : apply_pattern (TemplatePoolArrays , {"class" : "PoolColorArray" , "type" : "Variant::POOL_COLOR_ARRAY" , "element" : "Color" }),
420
+ "PoolStringArray" : apply_pattern (TemplateSimplePoolArrays ,{"class" : "PoolStringArray" , "type" : "Variant::POOL_STRING_ARRAY" , "element" : "String" }),
421
421
}
422
422
class_name = cls ['name' ]
423
- constructor_name = apply_parttern (TemplateConstructorName , {"class" : class_name })
424
- constructor_declare = apply_parttern (TemplateConstructorDeclare , {"class" : class_name })
423
+ constructor_name = apply_pattern (TemplateConstructorName , {"class" : class_name })
424
+ constructor_declare = apply_pattern (TemplateConstructorDeclare , {"class" : class_name })
425
425
426
426
initializer = ''
427
427
if class_name in ConstructorInitializers :
428
428
initializer = ConstructorInitializers [class_name ]
429
- consturctor = apply_parttern (TemplateConstructor , {
429
+ consturctor = apply_pattern (TemplateConstructor , {
430
430
'class' : class_name ,
431
431
'type' : VariantTypes [class_name ],
432
432
'func' : constructor_name ,
@@ -479,21 +479,21 @@ def generate_members(cls):
479
479
type = p ['type' ]
480
480
name = p ['name' ]
481
481
native_name = p ['native' ]
482
- getters += apply_parttern (TemplateGetterItem , {
482
+ getters += apply_pattern (TemplateGetterItem , {
483
483
'index' : str (i ),
484
- 'value' : apply_parttern (GodotToJSTemplates [type ], { 'arg' : apply_parttern ('ptr->${native}' , {'native' : native_name }) })
484
+ 'value' : apply_pattern (GodotToJSTemplates [type ], { 'arg' : apply_pattern ('ptr->${native}' , {'native' : native_name }) })
485
485
})
486
- setters += apply_parttern (TemplateSetterItem , {
486
+ setters += apply_pattern (TemplateSetterItem , {
487
487
'index' : str (i ),
488
488
'name' : name ,
489
489
'native' : native_name ,
490
490
'type' : VariantTypes [type ],
491
491
'type_name' : type ,
492
492
'class' : class_name ,
493
- 'value' : apply_parttern (JSToGodotTemplates [type ], {'arg' : 'argv[0]' })
493
+ 'value' : apply_pattern (JSToGodotTemplates [type ], {'arg' : 'argv[0]' })
494
494
})
495
- bindings += apply_parttern (TemplateItemBinding , {'index' : str (i ), 'name' : name , 'type' : VariantTypes [class_name ]})
496
- return apply_parttern (Template , {
495
+ bindings += apply_pattern (TemplateItemBinding , {'index' : str (i ), 'name' : name , 'type' : VariantTypes [class_name ]})
496
+ return apply_pattern (Template , {
497
497
'class' : class_name ,
498
498
'getters' : getters ,
499
499
'setters' : setters ,
@@ -509,12 +509,12 @@ def generate_methods(cls):
509
509
[](JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
510
510
ECMAScriptGCHandler *bind = BINDING_DATA_FROM_JS(ctx, this_val);
511
511
${class} *ptr = bind->get${class}();\
512
- ${arg_declars }
512
+ ${arg_declares }
513
513
${call}
514
514
return ${return};
515
515
},
516
516
${argc});'''
517
- TemplateArgDeclear = '''
517
+ TemplateArgDeclare = '''
518
518
#ifdef DEBUG_METHODS_ENABLED
519
519
ERR_FAIL_COND_V(!QuickJSBinder::validate_type(ctx, ${type}, argv[${index}]), (JS_ThrowTypeError(ctx, "${type_name} expected for argument ${index} of ${class}.${name}")));
520
520
#endif
@@ -524,39 +524,39 @@ def generate_methods(cls):
524
524
bindings = ''
525
525
for m in cls ['methods' ]:
526
526
args = ''
527
- arg_declars = ''
527
+ arg_declares = ''
528
528
for i in range (len (m ['arguments' ])):
529
529
arg = m ['arguments' ][i ]
530
530
arg_type = arg ['type' ]
531
- arg_declars += apply_parttern ( TemplateArgDeclear , {
531
+ arg_declares += apply_pattern ( TemplateArgDeclare , {
532
532
'index' : str (i ),
533
533
'type' : VariantTypes [arg_type ],
534
534
'type_name' : arg_type ,
535
535
'class' : class_name ,
536
536
'name' : m ['name' ],
537
- 'arg' : apply_parttern (JSToGodotTemplates [arg_type ], {'arg' : 'argv[' + str (i ) + ']' }),
537
+ 'arg' : apply_pattern (JSToGodotTemplates [arg_type ], {'arg' : 'argv[' + str (i ) + ']' }),
538
538
'godot_type' : GodotTypeNames [arg_type ],
539
539
})
540
540
if i > 0 : args += ', '
541
541
args += 'arg' + str (i )
542
- CallTemplate = ('' if m ['return' ] == 'void' else (apply_parttern (TemplateReturnValue , {"godot_type" : GodotTypeNames [m ['return' ]]}))) + 'ptr->${native_method}(${args});'
543
- call = apply_parttern (CallTemplate , {'native_method' : m ['native_method' ], 'args' : args })
544
- bindings += apply_parttern (TemplateMethod , {
542
+ CallTemplate = ('' if m ['return' ] == 'void' else (apply_pattern (TemplateReturnValue , {"godot_type" : GodotTypeNames [m ['return' ]]}))) + 'ptr->${native_method}(${args});'
543
+ call = apply_pattern (CallTemplate , {'native_method' : m ['native_method' ], 'args' : args })
544
+ bindings += apply_pattern (TemplateMethod , {
545
545
"class" : class_name ,
546
546
"type" : VariantTypes [class_name ],
547
547
"name" : m ['name' ],
548
548
"call" : call ,
549
- "arg_declars " : arg_declars ,
549
+ "arg_declares " : arg_declares ,
550
550
"argc" : str (len (m ['arguments' ])),
551
- "return" : 'JS_UNDEFINED' if m ['return' ] == 'void' else apply_parttern (GodotToJSTemplates [m ['return' ]], {'arg' : 'ret' }),
551
+ "return" : 'JS_UNDEFINED' if m ['return' ] == 'void' else apply_pattern (GodotToJSTemplates [m ['return' ]], {'arg' : 'ret' }),
552
552
})
553
553
return bindings
554
554
555
555
def generate_constants (cls ):
556
556
ConstTemplate = '\t binder->get_builtin_binder().register_constant(${type}, "${name}", ${value});\n '
557
557
bindings = ''
558
558
for c in cls ['constants' ]:
559
- bindings += apply_parttern (ConstTemplate , {
559
+ bindings += apply_pattern (ConstTemplate , {
560
560
"name" : c ['name' ],
561
561
"type" : VariantTypes [class_name ],
562
562
"value" : c ['value' ]
@@ -572,7 +572,7 @@ def genertate_operators(cls):
572
572
'operator==' : '==' ,
573
573
'operator<' : '<'
574
574
}
575
- TargetDeclearTemplate = '''
575
+ TargetDeclareTemplate = '''
576
576
#ifdef DEBUG_METHODS_ENABLED
577
577
ERR_FAIL_COND_V(!QuickJSBinder::validate_type(ctx, ${type}, argv[1]), (JS_ThrowTypeError(ctx, "${target_class} expected for ${class}.${operator}")));
578
578
#endif
@@ -584,7 +584,7 @@ def genertate_operators(cls):
584
584
JS_NewCFunction(ctx, [](JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
585
585
ECMAScriptGCHandler *bind = BINDING_DATA_FROM_JS(ctx, argv[0]);
586
586
${class} *ptr = bind->get${class}();\
587
- ${target_declear }
587
+ ${target_declare }
588
588
${call}
589
589
return ${return};
590
590
},
@@ -607,29 +607,29 @@ def genertate_operators(cls):
607
607
js_op = 'neg'
608
608
609
609
args = ''
610
- target_declear = ''
610
+ target_declare = ''
611
611
if argc > 1 :
612
612
arg_class = o ['arguments' ][0 ]['type' ]
613
- target_declear = apply_parttern ( TargetDeclearTemplate , {
613
+ target_declare = apply_pattern ( TargetDeclareTemplate , {
614
614
'target_class' : arg_class ,
615
615
'type' : VariantTypes [arg_class ],
616
616
'class' : class_name ,
617
617
'operator' : o ['native_method' ],
618
618
})
619
619
args = '*target'
620
- CallTemplate = ('' if o ['return' ] == 'void' else apply_parttern (TemplateReturnValue , {'godot_type' : GodotTypeNames [o ['return' ]] })) + 'ptr->${op}(${args});'
621
- call = apply_parttern (CallTemplate , {'op' : op , 'args' : args })
622
- bindings += apply_parttern (OperatorTemplate , {
620
+ CallTemplate = ('' if o ['return' ] == 'void' else apply_pattern (TemplateReturnValue , {'godot_type' : GodotTypeNames [o ['return' ]] })) + 'ptr->${op}(${args});'
621
+ call = apply_pattern (CallTemplate , {'op' : op , 'args' : args })
622
+ bindings += apply_pattern (OperatorTemplate , {
623
623
'type' : VariantTypes [class_name ],
624
624
'class' : class_name ,
625
625
'js_op' : js_op ,
626
626
'call' : call ,
627
627
'name' : o ['name' ],
628
- 'target_declear ' : target_declear ,
629
- "return" : 'JS_UNDEFINED' if o ['return' ] == 'void' else apply_parttern (GodotToJSTemplates [o ['return' ]], {'arg' : 'ret' }),
628
+ 'target_declare ' : target_declare ,
629
+ "return" : 'JS_UNDEFINED' if o ['return' ] == 'void' else apply_pattern (GodotToJSTemplates [o ['return' ]], {'arg' : 'ret' }),
630
630
'argc' : str (argc )
631
631
})
632
- bindings += apply_parttern ('''
632
+ bindings += apply_pattern ('''
633
633
operators.push_back(base_operators);
634
634
binder->get_builtin_binder().get_cross_type_operators(${type}, operators);
635
635
binder->get_builtin_binder().register_operators(${type}, operators);
@@ -646,21 +646,21 @@ def genertate_operators(cls):
646
646
}
647
647
'''
648
648
class_name = cls ['name' ]
649
- property_declare = apply_parttern (TemplateDeclar , {"class" : class_name })
650
- property_defines = apply_parttern (TemplateBindDefine , {
649
+ property_declare = apply_pattern (TemplateDeclar , {"class" : class_name })
650
+ property_defines = apply_pattern (TemplateBindDefine , {
651
651
"class" : class_name ,
652
652
"members" : generate_members (cls ) if len (cls ['properties' ]) else '' ,
653
653
"methods" : generate_methods (cls ),
654
654
"constants" : generate_constants (cls ),
655
655
"operators" : genertate_operators (cls ),
656
656
})
657
- property_bind = apply_parttern (TemplateBind , {"class" : class_name })
657
+ property_bind = apply_pattern (TemplateBind , {"class" : class_name })
658
658
return property_declare , property_defines , property_bind
659
659
660
660
661
661
def generate_class_bind_action (cls , constructor ):
662
662
Template = '\t register_builtin_class(${type}, "${class}", ${constructor}, ${argc});\n '
663
- return apply_parttern (Template , {
663
+ return apply_pattern (Template , {
664
664
'class' : cls ['name' ],
665
665
'constructor' : constructor ,
666
666
'type' : VariantTypes [cls ['name' ]],
@@ -703,7 +703,7 @@ def generate_builtin_bindings():
703
703
definitions += property_defines
704
704
bindings += property_bind
705
705
706
- output = apply_parttern (Template , {
706
+ output = apply_pattern (Template , {
707
707
'declarations' : declarations ,
708
708
'bindings' : bindings ,
709
709
'definitions' : definitions ,
0 commit comments