diff --git a/binding_generator.py b/binding_generator.py index e7609b2c..17bb8066 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -852,14 +852,14 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl if "operators" in builtin_api: for operator in builtin_api["operators"]: - if operator["name"] not in ["in", "xor"]: + if is_valid_cpp_operator(operator["name"]): if "right_type" in operator: result.append( - f'\t{correct_type(operator["return_type"])} operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const;' + f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const;' ) else: result.append( - f'\t{correct_type(operator["return_type"])} operator{operator["name"].replace("unary", "")}() const;' + f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}() const;' ) # Copy assignment. @@ -1291,10 +1291,10 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl if "operators" in builtin_api: for operator in builtin_api["operators"]: - if operator["name"] not in ["in", "xor"]: + if is_valid_cpp_operator(operator["name"]): if "right_type" in operator: result.append( - f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const {{' + f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const {{' ) (encode, arg_name) = get_encoded_arg("other", operator["right_type"], None) result += encode @@ -1304,7 +1304,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl result.append("}") else: result.append( - f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"].replace("unary", "")}() const {{' + f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}() const {{' ) result.append( f'\treturn internal::_call_builtin_operator_ptr<{get_gdextension_type(correct_type(operator["return_type"]))}>(_method_bindings.operator_{get_operator_id_name(operator["name"])}, (GDExtensionConstTypePtr)&opaque, (GDExtensionConstTypePtr)nullptr);' @@ -2719,8 +2719,8 @@ def correct_type(type_name, meta=None, use_alias=True): if meta is not None: if "int" in meta: return f"{meta}_t" - elif meta in type_conversion: - return type_conversion[type_name] + elif "char" in meta: + return f"{meta}_t" else: return meta if type_name in type_conversion: @@ -2832,6 +2832,38 @@ def get_operator_id_name(op): return op_id_map[op] +def get_operator_cpp_name(op): + op_cpp_map = { + "==": "==", + "!=": "!=", + "<": "<", + "<=": "<=", + ">": ">", + ">=": ">=", + "+": "+", + "-": "-", + "*": "*", + "/": "/", + "unary-": "-", + "unary+": "+", + "%": "%", + "<<": "<<", + ">>": ">>", + "&": "&", + "|": "|", + "^": "^", + "~": "~", + "and": "&&", + "or": "||", + "not": "!", + } + return op_cpp_map[op] + + +def is_valid_cpp_operator(op): + return op not in ["**", "xor", "in"] + + def get_default_value_for_type(type_name): if type_name == "int": return "0" diff --git a/include/godot_cpp/core/type_info.hpp b/include/godot_cpp/core/type_info.hpp index f368988e..b78f7e73 100644 --- a/include/godot_cpp/core/type_info.hpp +++ b/include/godot_cpp/core/type_info.hpp @@ -397,16 +397,17 @@ MAKE_TYPED_ARRAY_INFO(Callable, Variant::CALLABLE) MAKE_TYPED_ARRAY_INFO(Signal, Variant::SIGNAL) MAKE_TYPED_ARRAY_INFO(Dictionary, Variant::DICTIONARY) MAKE_TYPED_ARRAY_INFO(Array, Variant::ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedByteArray, Variant::PACKED_BYTE_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedInt32Array, Variant::PACKED_INT32_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedInt64Array, Variant::PACKED_INT64_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedFloat32Array, Variant::PACKED_FLOAT32_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedFloat64Array, Variant::PACKED_FLOAT64_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedStringArray, Variant::PACKED_STRING_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedVector4Array, Variant::PACKED_VECTOR4_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedColorArray, Variant::PACKED_COLOR_ARRAY) /* -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_BYTE_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_INT32_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_INT64_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_FLOAT32_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_FLOAT64_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_STRING_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_VECTOR2_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_VECTOR3_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_COLOR_ARRAY) MAKE_TYPED_ARRAY_INFO(IPAddress, Variant::STRING) */ diff --git a/include/godot_cpp/templates/safe_refcount.hpp b/include/godot_cpp/templates/safe_refcount.hpp index 12e6840a..98cb04b2 100644 --- a/include/godot_cpp/templates/safe_refcount.hpp +++ b/include/godot_cpp/templates/safe_refcount.hpp @@ -132,7 +132,7 @@ public: } } - _ALWAYS_INLINE_ explicit SafeNumeric(T p_value = static_cast(0)) { + _ALWAYS_INLINE_ explicit SafeNumeric(T p_value = static_cast(0)) { set(p_value); } }; diff --git a/test/project/main.gd b/test/project/main.gd index dadd4de6..b2625b9a 100644 --- a/test/project/main.gd +++ b/test/project/main.gd @@ -270,6 +270,12 @@ func _ready(): assert_equal(example_child.get_value1(), 11) assert_equal(example_child.get_value2(), 22) + # Test that the extension's library path is absolute and valid. + var library_path = Example.test_library_path() + assert_equal(library_path.begins_with("res://"), false) + assert_equal(library_path, ProjectSettings.globalize_path(library_path)) + assert_equal(FileAccess.file_exists(library_path), true) + exit_with_status() func _on_Example_custom_signal(signal_name, value): diff --git a/test/src/example.cpp b/test/src/example.cpp index a9418898..8075f551 100644 --- a/test/src/example.cpp +++ b/test/src/example.cpp @@ -204,6 +204,7 @@ void Example::_bind_methods() { ClassDB::bind_method(D_METHOD("test_str_utility"), &Example::test_str_utility); ClassDB::bind_method(D_METHOD("test_string_is_forty_two"), &Example::test_string_is_forty_two); ClassDB::bind_method(D_METHOD("test_string_resize"), &Example::test_string_resize); + ClassDB::bind_method(D_METHOD("test_typed_array_of_packed"), &Example::test_typed_array_of_packed); ClassDB::bind_method(D_METHOD("test_vector_ops"), &Example::test_vector_ops); ClassDB::bind_method(D_METHOD("test_vector_init_list"), &Example::test_vector_init_list); @@ -248,6 +249,8 @@ void Example::_bind_methods() { ClassDB::bind_static_method("Example", D_METHOD("test_static", "a", "b"), &Example::test_static); ClassDB::bind_static_method("Example", D_METHOD("test_static2"), &Example::test_static2); + ClassDB::bind_static_method("Example", D_METHOD("test_library_path"), &Example::test_library_path); + { MethodInfo mi; mi.arguments.push_back(PropertyInfo(Variant::STRING, "some_argument")); @@ -424,6 +427,19 @@ String Example::test_string_resize(String p_string) const { return p_string; } +TypedArray Example::test_typed_array_of_packed() const { + TypedArray arr; + PackedInt32Array packed_arr1; + packed_arr1.push_back(1); + packed_arr1.push_back(2); + arr.push_back(packed_arr1); + PackedInt32Array packed_arr2; + packed_arr2.push_back(3); + packed_arr2.push_back(4); + arr.push_back(packed_arr2); + return arr; +} + int Example::test_vector_ops() const { PackedInt32Array arr; arr.push_back(10); @@ -695,6 +711,12 @@ String Example::test_use_engine_singleton() const { return OS::get_singleton()->get_name(); } +String Example::test_library_path() { + String library_path; + internal::gdextension_interface_get_library_path(internal::library, library_path._native_ptr()); + return library_path; +} + void ExampleRuntime::_bind_methods() { ClassDB::bind_method(D_METHOD("set_prop_value", "value"), &ExampleRuntime::set_prop_value); ClassDB::bind_method(D_METHOD("get_prop_value"), &ExampleRuntime::get_prop_value); diff --git a/test/src/example.h b/test/src/example.h index 7f3dfaa6..6d88cf11 100644 --- a/test/src/example.h +++ b/test/src/example.h @@ -134,6 +134,7 @@ public: String test_str_utility() const; bool test_string_is_forty_two(const String &p_str) const; String test_string_resize(String p_original) const; + TypedArray test_typed_array_of_packed() const; int test_vector_ops() const; int test_vector_init_list() const; @@ -194,6 +195,8 @@ public: GDVIRTUAL1(_do_something_virtual_with_control, Control *); String test_use_engine_singleton() const; + + static String test_library_path(); }; VARIANT_ENUM_CAST(Example::Constants); diff --git a/tools/web.py b/tools/web.py index dea42b26..c8f07c55 100644 --- a/tools/web.py +++ b/tools/web.py @@ -39,7 +39,7 @@ def generate(env): env.Append(LINKFLAGS=["-sUSE_PTHREADS=1"]) # Build as side module (shared library). - env.Append(CPPFLAGS=["-sSIDE_MODULE=1"]) + env.Append(CCFLAGS=["-sSIDE_MODULE=1"]) env.Append(LINKFLAGS=["-sSIDE_MODULE=1"]) # Force wasm longjmp mode.