33
44DIR = os .path .abspath ( os .path .dirname (__file__ ) )
55OUTPUT_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' ))
77
88VariantTypes = {
99 "boolean" : "Variant::BOOL" ,
104104 "Variant" : 'QuickJSBinder::variant_to_var(ctx, ${arg})' ,
105105}
106106
107- def apply_parttern (template , values ):
107+ def apply_pattern (template , values ):
108108 for key in values :
109109 template = template .replace ( '${' + key + '}' , values [key ])
110110 return template
@@ -411,22 +411,22 @@ def generate_constructor(cls):
411411 }
412412 }
413413''' ,
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" }),
421421 }
422422 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 })
425425
426426 initializer = ''
427427 if class_name in ConstructorInitializers :
428428 initializer = ConstructorInitializers [class_name ]
429- consturctor = apply_parttern (TemplateConstructor , {
429+ consturctor = apply_pattern (TemplateConstructor , {
430430 'class' : class_name ,
431431 'type' : VariantTypes [class_name ],
432432 'func' : constructor_name ,
@@ -479,21 +479,21 @@ def generate_members(cls):
479479 type = p ['type' ]
480480 name = p ['name' ]
481481 native_name = p ['native' ]
482- getters += apply_parttern (TemplateGetterItem , {
482+ getters += apply_pattern (TemplateGetterItem , {
483483 '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 }) })
485485 })
486- setters += apply_parttern (TemplateSetterItem , {
486+ setters += apply_pattern (TemplateSetterItem , {
487487 'index' : str (i ),
488488 'name' : name ,
489489 'native' : native_name ,
490490 'type' : VariantTypes [type ],
491491 'type_name' : type ,
492492 'class' : class_name ,
493- 'value' : apply_parttern (JSToGodotTemplates [type ], {'arg' : 'argv[0]' })
493+ 'value' : apply_pattern (JSToGodotTemplates [type ], {'arg' : 'argv[0]' })
494494 })
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 , {
497497 'class' : class_name ,
498498 'getters' : getters ,
499499 'setters' : setters ,
@@ -509,12 +509,12 @@ def generate_methods(cls):
509509 [](JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
510510 ECMAScriptGCHandler *bind = BINDING_DATA_FROM_JS(ctx, this_val);
511511 ${class} *ptr = bind->get${class}();\
512- ${arg_declars }
512+ ${arg_declares }
513513 ${call}
514514 return ${return};
515515 },
516516 ${argc});'''
517- TemplateArgDeclear = '''
517+ TemplateArgDeclare = '''
518518#ifdef DEBUG_METHODS_ENABLED
519519 ERR_FAIL_COND_V(!QuickJSBinder::validate_type(ctx, ${type}, argv[${index}]), (JS_ThrowTypeError(ctx, "${type_name} expected for argument ${index} of ${class}.${name}")));
520520#endif
@@ -524,39 +524,39 @@ def generate_methods(cls):
524524 bindings = ''
525525 for m in cls ['methods' ]:
526526 args = ''
527- arg_declars = ''
527+ arg_declares = ''
528528 for i in range (len (m ['arguments' ])):
529529 arg = m ['arguments' ][i ]
530530 arg_type = arg ['type' ]
531- arg_declars += apply_parttern ( TemplateArgDeclear , {
531+ arg_declares += apply_pattern ( TemplateArgDeclare , {
532532 'index' : str (i ),
533533 'type' : VariantTypes [arg_type ],
534534 'type_name' : arg_type ,
535535 'class' : class_name ,
536536 '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 ) + ']' }),
538538 'godot_type' : GodotTypeNames [arg_type ],
539539 })
540540 if i > 0 : args += ', '
541541 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 , {
545545 "class" : class_name ,
546546 "type" : VariantTypes [class_name ],
547547 "name" : m ['name' ],
548548 "call" : call ,
549- "arg_declars " : arg_declars ,
549+ "arg_declares " : arg_declares ,
550550 "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' }),
552552 })
553553 return bindings
554554
555555 def generate_constants (cls ):
556556 ConstTemplate = '\t binder->get_builtin_binder().register_constant(${type}, "${name}", ${value});\n '
557557 bindings = ''
558558 for c in cls ['constants' ]:
559- bindings += apply_parttern (ConstTemplate , {
559+ bindings += apply_pattern (ConstTemplate , {
560560 "name" : c ['name' ],
561561 "type" : VariantTypes [class_name ],
562562 "value" : c ['value' ]
@@ -572,7 +572,7 @@ def genertate_operators(cls):
572572 'operator==' : '==' ,
573573 'operator<' : '<'
574574 }
575- TargetDeclearTemplate = '''
575+ TargetDeclareTemplate = '''
576576#ifdef DEBUG_METHODS_ENABLED
577577 ERR_FAIL_COND_V(!QuickJSBinder::validate_type(ctx, ${type}, argv[1]), (JS_ThrowTypeError(ctx, "${target_class} expected for ${class}.${operator}")));
578578#endif
@@ -584,7 +584,7 @@ def genertate_operators(cls):
584584 JS_NewCFunction(ctx, [](JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
585585 ECMAScriptGCHandler *bind = BINDING_DATA_FROM_JS(ctx, argv[0]);
586586 ${class} *ptr = bind->get${class}();\
587- ${target_declear }
587+ ${target_declare }
588588 ${call}
589589 return ${return};
590590 },
@@ -607,29 +607,29 @@ def genertate_operators(cls):
607607 js_op = 'neg'
608608
609609 args = ''
610- target_declear = ''
610+ target_declare = ''
611611 if argc > 1 :
612612 arg_class = o ['arguments' ][0 ]['type' ]
613- target_declear = apply_parttern ( TargetDeclearTemplate , {
613+ target_declare = apply_pattern ( TargetDeclareTemplate , {
614614 'target_class' : arg_class ,
615615 'type' : VariantTypes [arg_class ],
616616 'class' : class_name ,
617617 'operator' : o ['native_method' ],
618618 })
619619 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 , {
623623 'type' : VariantTypes [class_name ],
624624 'class' : class_name ,
625625 'js_op' : js_op ,
626626 'call' : call ,
627627 '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' }),
630630 'argc' : str (argc )
631631 })
632- bindings += apply_parttern ('''
632+ bindings += apply_pattern ('''
633633 operators.push_back(base_operators);
634634 binder->get_builtin_binder().get_cross_type_operators(${type}, operators);
635635 binder->get_builtin_binder().register_operators(${type}, operators);
@@ -646,21 +646,21 @@ def genertate_operators(cls):
646646}
647647'''
648648 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 , {
651651 "class" : class_name ,
652652 "members" : generate_members (cls ) if len (cls ['properties' ]) else '' ,
653653 "methods" : generate_methods (cls ),
654654 "constants" : generate_constants (cls ),
655655 "operators" : genertate_operators (cls ),
656656 })
657- property_bind = apply_parttern (TemplateBind , {"class" : class_name })
657+ property_bind = apply_pattern (TemplateBind , {"class" : class_name })
658658 return property_declare , property_defines , property_bind
659659
660660
661661def generate_class_bind_action (cls , constructor ):
662662 Template = '\t register_builtin_class(${type}, "${class}", ${constructor}, ${argc});\n '
663- return apply_parttern (Template , {
663+ return apply_pattern (Template , {
664664 'class' : cls ['name' ],
665665 'constructor' : constructor ,
666666 'type' : VariantTypes [cls ['name' ]],
@@ -703,7 +703,7 @@ def generate_builtin_bindings():
703703 definitions += property_defines
704704 bindings += property_bind
705705
706- output = apply_parttern (Template , {
706+ output = apply_pattern (Template , {
707707 'declarations' : declarations ,
708708 'bindings' : bindings ,
709709 'definitions' : definitions ,
0 commit comments