1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge pull request #27726 from DasoTD:fix/string-property-binding

Fix string property bindings in JS generator #27726

Fixes #27712

This PR fixes the binding generation logic in embindgen.py to correctly handle enum and string properties:
Enum properties now use binding_utils::underlying_ptr(&Class::property).
Standard string properties are bound directly with &Class::property.
Other properties continue to use the default template.

Testing:
Verified generated bindings locally to ensure the expected output for enums and strings.
This commit is contained in:
Timi
2025-09-25 08:59:27 +01:00
committed by GitHub
parent 255d1d2b0c
commit 9282afa0c7
+34 -6
View File
@@ -320,7 +320,6 @@ class Namespace(object):
class JSWrapperGenerator(object):
def __init__(self, preprocessor_definitions=None):
self.bindings = []
self.wrapper_funcs = []
@@ -333,6 +332,29 @@ class JSWrapperGenerator(object):
)
self.class_idx = 0
def _is_string_type(self, tp: str) -> bool:
"""Check if a type should be treated as string in bindings."""
string_types = {
"std::string",
"char",
"signed char",
"unsigned char",
}
return tp in string_types
def _generate_class_properties(self, class_info, class_bindings):
# Generate bindings for properties
for prop in class_info.props:
if prop.tp in type_dict and not self._is_string_type(prop.tp):
_class_property = class_property_enum_template
else:
_class_property = class_property_template
class_bindings.append(_class_property.substitute(
js_name=prop.name,
cpp_name='::'.join([class_info.cname, prop.name])
))
def add_class(self, stype, name, decl):
class_info = ClassInfo(name, decl)
class_info.decl_idx = self.class_idx
@@ -893,11 +915,17 @@ class JSWrapperGenerator(object):
# Generate bindings for properties
for property in class_info.props:
_class_property = class_property_enum_template if property.tp in type_dict else class_property_template
class_bindings.append(_class_property.substitute(js_name=property.name, cpp_name='::'.join(
[class_info.cname, property.name])))
# Generate bindings for properties(prop)
for prop in class_info.props:
if prop.tp in type_dict and not self._is_string_type(prop.tp):
_class_property = class_property_enum_template
else:
_class_property = class_property_template
class_bindings.append(_class_property.substitute(
js_name=prop.name,
cpp_name='::'.join([class_info.cname, prop.name])
))
dv = ''
base = Template("""base<$base>""")