@@ -79,14 +79,19 @@ def generate_option(self, struct_name, struct_details, all_type_details={}):
79
79
# TODO: make some/none-ordering-agnostic!
80
80
some_variant_name = option_value_details [0 ].tag_value # var_name
81
81
none_variant_name = option_value_details [1 ].var_name
82
- field_details = option_value_details [0 ].fields [0 ]
82
+ constructor_argument_types = option_value_details [0 ].fields
83
+ field_details = constructor_argument_types [0 ]
83
84
84
85
assert field_details .var_name == 'some'
85
86
86
87
raw_rust_type = field_details .rust_obj
87
88
swift_type = field_details .swift_type
88
89
nullable_swift_type = swift_type + '?'
89
90
91
+
92
+ array_parsing_prep = ''
93
+ array_return_line = None
94
+
90
95
native_conversion_prefix = ''
91
96
native_conversion_suffix = ''
92
97
swift_local_conversion_prefix = ''
@@ -97,6 +102,23 @@ def generate_option(self, struct_name, struct_details, all_type_details={}):
97
102
native_conversion_suffix = '.cOpaqueStruct!'
98
103
swift_local_conversion_prefix = f'{ swift_type } (pointer: '
99
104
swift_local_conversion_suffix = ')'
105
+ elif swift_type .startswith ('[' ):
106
+ prepared_arguments = ConversionHelper .prepare_swift_to_native_arguments (constructor_argument_types , array_unwrapping_preparation_only = True )
107
+ array_parsing_prep = f"""
108
+ { prepared_arguments ['native_call_prep' ].replace ('some' , 'value' )}
109
+ let somevalue = Bindings.new_{ raw_rust_type } Wrapper(array: valueUnwrapped)
110
+ // try! self.addAnchor(anchor: somevalue)
111
+ somevalue.dangle()
112
+ """
113
+ native_conversion_prefix = 'some'
114
+ native_conversion_suffix = '.cOpaqueStruct!'
115
+
116
+ value_return_wrappers = ConversionHelper .prepare_return_value (field_details , is_clone_method = False , is_raw_property_getter = True )
117
+ current_swift_return_type = value_return_wrappers ['swift_type' ]
118
+ current_replacement = 'return ' + value_return_wrappers ["prefix" ] + 'self.cOpaqueStruct!.varName' + value_return_wrappers ["suffix" ]
119
+ current_replacement = current_replacement .replace ('self.cOpaqueStruct!.varName' , f'self.cOpaqueStruct!.{ field_details .var_name } ' )
120
+ array_return_line = current_replacement
121
+
100
122
101
123
# DEFAULT CONSTRUCTOR
102
124
@@ -106,6 +128,7 @@ def generate_option(self, struct_name, struct_details, all_type_details={}):
106
128
self.cOpaqueStruct = { struct_name } ()
107
129
if let value = value {{
108
130
self.cOpaqueStruct!.tag = { some_variant_name }
131
+ { array_parsing_prep }
109
132
self.cOpaqueStruct!.some = { native_conversion_prefix } value{ native_conversion_suffix }
110
133
}} else {{
111
134
self.cOpaqueStruct!.tag = { none_variant_name }
@@ -118,13 +141,18 @@ def generate_option(self, struct_name, struct_details, all_type_details={}):
118
141
current_replacement = current_replacement .replace ('methodName' , current_method_name )
119
142
current_replacement = current_replacement .replace ('swift_arguments' , '' )
120
143
current_replacement = current_replacement .replace ('-> Void' , '-> ' + nullable_swift_type )
144
+
145
+ some_return_line = f'''return { swift_local_conversion_prefix } self.cOpaqueStruct!.some{ swift_local_conversion_suffix } '''
146
+ if array_return_line is not None :
147
+ some_return_line = array_return_line
148
+
121
149
current_replacement = current_replacement .replace ('/* NATIVE_CALL_PREP */' , f'''
122
150
123
151
if self.cOpaqueStruct!.tag == { none_variant_name } {{
124
152
return nil
125
153
}}
126
154
if self.cOpaqueStruct!.tag == { some_variant_name } {{
127
- return { swift_local_conversion_prefix } self.cOpaqueStruct!.some { swift_local_conversion_suffix }
155
+ { some_return_line }
128
156
}}
129
157
assert(false, "invalid option enum value")
130
158
return nil
0 commit comments