Skip to content

Commit c56f793

Browse files
authored
Merge pull request #100 from BrianMWest/master
feature: update for Godot 3.3-stable
2 parents fdbe206 + de6312e commit c56f793

File tree

11 files changed

+87
-90
lines changed

11 files changed

+87
-90
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [push]
55
# Global Cache Settings
66
env:
77
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
8-
GODOT_BASE_BRANCH: '3.2.3-stable'
8+
GODOT_BASE_BRANCH: '3.3-stable'
99
BASE_BRANCH: master
1010
SCONS_CACHE_LIMIT: 4096
1111

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ You can also get the binaries with lastest commits from the [github build action
2121
### Compilation
2222
* Clone the source code of [godot](https://github.com/godotengine/godot)
2323
* Clone this module and put it into `godot/modules/` and make sure the folder name of this module is `ECMAScript`
24-
* [Recompile the godot engine](https://docs.godotengine.org/en/3.2/development/compiling/index.html) <b>(Only MinGW is supported on Windows for now!)</b>
24+
* [Recompile the godot engine](https://docs.godotengine.org/en/3.3/development/compiling/index.html) <b>(Only MinGW is supported on Windows for now!)</b>
2525

2626
![Build Godot with ECMAScript](https://github.com/GodotExplorer/ECMAScript/workflows/Build%20Godot%20with%20ECMAScript/badge.svg)
2727

SCsub

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def dump_text_file_to_cpp(file):
1919
length = len(lines)
2020
for i in range(length):
2121
line = lines[i].replace('"', '\\"')
22-
line = '\t"' + line + '\\n"';
22+
line = '\t"' + line + '\\n"'
2323
if i < length -1:
2424
line += "\n"
2525
source += line
@@ -57,7 +57,7 @@ sources = [
5757

5858
if env['tools']:
5959
with open_file("tools/godot.d.ts.gen.cpp", "w") as f:
60-
text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::BUILTIN_DECLEARATION_TEXT = \n${source};';
60+
text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::BUILTIN_DECLARATION_TEXT = \n${source};'
6161
f.write(text.replace('${source}', dump_text_file_to_cpp("misc/godot.d.ts")))
6262
with open_file("tools/tsconfig.json.gen.cpp", "w") as f:
6363
text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::TSCONFIG_CONTENT = \n${source};'
@@ -71,5 +71,4 @@ if env['tools']:
7171
env_module.add_source_files(env.modules_sources, 'tools/*.cpp')
7272

7373
env_module.Append(CPPPATH=["#modules/ECMAScript"])
74-
env_module.Append(CXXFLAGS=["-std=c++11"])
7574
env_module.add_source_files(env.modules_sources, sources)

generate_builtin_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331
]
332332
}
333333

334-
def apply_parttern(template, values):
334+
def apply_pattern(template, values):
335335
for key in values:
336336
template = template.replace( '${' + key + '}', values[key])
337337
return template
@@ -405,15 +405,15 @@ def parse_class(cls):
405405
if class_name in IGNORED_PROPS and const_name in IGNORED_PROPS[class_name]:
406406
continue
407407
constants.append(dict(c.attrib))
408-
return json.loads(apply_parttern(json.dumps(ret), {
408+
return json.loads(apply_pattern(json.dumps(ret), {
409409
'class_name': class_name,
410410
}))
411411

412412
def generate_api_json(MODULE_DIR):
413413
DOCS_DIR = os.path.abspath(os.path.join(MODULE_DIR, "../../doc/classes"))
414414
if not os.path.isdir(DOCS_DIR) and len(sys.argv) > 1:
415415
DOCS_DIR = sys.argv[-1]
416-
OUTPUT_FILE = os.path.join(MODULE_DIR, "buitin_api.gen.json");
416+
OUTPUT_FILE = os.path.join(MODULE_DIR, "builtin_api.gen.json")
417417

418418
classes = []
419419
for cls in BUILTIN_CLASSES:

quickjs/builtin_binding_generator.py

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
DIR = os.path.abspath( os.path.dirname(__file__) )
55
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'))
77

88
VariantTypes = {
99
"boolean": "Variant::BOOL",
@@ -104,7 +104,7 @@
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 = '\tbinder->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

661661
def generate_class_bind_action(cls, constructor):
662662
Template = '\tregister_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,

quickjs/quickjs_binder.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
#include "editor/editor_settings.h"
1717
#endif
1818

19-
uint32_t QuickJSBinder::global_context_id = 0;
20-
uint64_t QuickJSBinder::global_transfer_id = 0;
19+
SafeNumeric<uint32_t> QuickJSBinder::global_context_id;
20+
SafeNumeric<uint64_t> QuickJSBinder::global_transfer_id;
21+
2122
HashMap<uint64_t, Variant> QuickJSBinder::transfer_deopot;
2223
Map<String, const char *> QuickJSBinder::class_remap;
2324
List<String> compiling_modules;
@@ -187,7 +188,7 @@ JSValue QuickJSBinder::object_method(JSContext *ctx, JSValueConst this_val, int
187188
}
188189
ERR_PRINTS(obj->get_class() + "." + mb->get_name() + ENDL + err_message + ENDL + stack_message);
189190
JS_FreeValue(ctx, ret);
190-
ret = JS_ThrowTypeError(ctx, err_message.utf8().get_data());
191+
ret = JS_ThrowTypeError(ctx, "%s", err_message.utf8().get_data());
191192
}
192193
#endif
193194

@@ -804,7 +805,7 @@ JSClassID QuickJSBinder::register_class(const ClassDB::ClassInfo *p_cls) {
804805
if (class_remap.has(p_cls->name)) {
805806
data.class_name = class_remap[p_cls->name];
806807
data.jsclass.class_name = class_remap[p_cls->name];
807-
if (data.jsclass.class_name == "") {
808+
if (strcmp(data.jsclass.class_name, "") == 0) {
808809
return 0;
809810
}
810811
} else {
@@ -1152,7 +1153,7 @@ void QuickJSBinder::add_godot_globals() {
11521153
}
11531154
}
11541155

1155-
// buitin functions
1156+
// builtin functions
11561157
for (int i = 0; i < Expression::FUNC_MAX; ++i) {
11571158
Expression::BuiltinFunc func = (Expression::BuiltinFunc)i;
11581159
String name = Expression::get_func_name(func);
@@ -1211,7 +1212,7 @@ void QuickJSBinder::add_godot_globals() {
12111212
}
12121213

12131214
QuickJSBinder::QuickJSBinder() {
1214-
context_id = global_context_id++;
1215+
context_id = QuickJSBinder::global_context_id.increment();
12151216
internal_godot_method_id = 0;
12161217
internal_godot_indexed_property_id = 0;
12171218
godot_allocator.js_malloc = QuickJSBinder::js_binder_malloc;
@@ -2214,7 +2215,7 @@ const ECMAClassInfo *QuickJSBinder::parse_ecma_class_from_module(ModuleCache *p_
22142215
if (!JS_IsFunction(ctx, default_entry)) {
22152216
String err = "Failed parse ECMAClass from script " + p_path + ENDL "\t" + "Default export entry must be a godot class!";
22162217
ERR_PRINTS(err);
2217-
JS_ThrowTypeError(ctx, err.utf8().get_data());
2218+
JS_ThrowTypeError(ctx, "%s", err.utf8().get_data());
22182219
goto fail;
22192220
}
22202221
ecma_class = register_ecma_class(default_entry, p_path);
@@ -2320,7 +2321,7 @@ JSValue QuickJSBinder::godot_abandon_value(JSContext *ctx, JSValue this_val, int
23202321

23212322
uint64_t id = 0;
23222323
if (valid) {
2323-
id = atomic_increment(&global_transfer_id);
2324+
id = QuickJSBinder::global_transfer_id.increment();
23242325
GLOBAL_LOCK_FUNCTION
23252326
transfer_deopot.set(id, gd_value);
23262327
}

quickjs/quickjs_binder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class QuickJSBinder : public ECMAScriptBinder {
3030
QuickJSBuiltinBinder builtin_binder;
3131

3232
protected:
33-
static uint32_t global_context_id;
34-
static uint64_t global_transfer_id;
33+
static SafeNumeric<uint32_t> global_context_id;
34+
static SafeNumeric<uint64_t> global_transfer_id;
3535
JSRuntime *runtime;
3636
JSContext *ctx;
3737
JSMallocFunctions godot_allocator;

0 commit comments

Comments
 (0)