@@ -204,10 +204,40 @@ void MCScriptAddExportToModule(MCScriptModuleBuilderRef self, uindex_t p_definit
204204 }
205205}
206206
207+ void MCScriptAddImportToModuleWithIndex (MCScriptModuleBuilderRef self, uindex_t p_module_index, MCNameRef p_name, MCScriptDefinitionKind p_kind, uindex_t p_type_index, uindex_t p_def_index)
208+ {
209+ uindex_t t_imp_index;
210+ if (!__extend_array (self, self -> module . imported_definitions, self -> module . imported_definition_count, t_imp_index) ||
211+ !MCMemoryNew ((MCScriptExternalDefinition*&)self -> module . definitions[p_def_index]))
212+ {
213+ self -> valid = false ;
214+ return ;
215+ }
216+
217+ __assign_definition_name (self, p_def_index, p_name);
218+
219+ MCScriptImportedDefinition *t_import;
220+ t_import = &self -> module . imported_definitions[t_imp_index];
221+
222+ t_import -> module = p_module_index;
223+ t_import -> kind = p_kind;
224+ t_import -> name = MCValueRetain (p_name);
225+ // t_import -> type = MCValueRetain(p_type);
226+
227+ MCScriptExternalDefinition *t_definition;
228+ t_definition = static_cast <MCScriptExternalDefinition *>(self -> module . definitions[p_def_index]);
229+
230+ t_definition -> kind = kMCScriptDefinitionKindExternal ;
231+ t_definition -> index = t_imp_index;
232+ }
233+
207234void MCScriptAddImportToModule (MCScriptModuleBuilderRef self, uindex_t p_index, MCNameRef p_name, MCScriptDefinitionKind p_kind, uindex_t p_type_index, uindex_t & r_index)
208235{
209236 if (self == nil || !self -> valid)
237+ {
238+ r_index = 0 ;
210239 return ;
240+ }
211241
212242 for (uindex_t i = 0 ; i < self -> module . imported_definition_count; i++)
213243 if (MCNameIsEqualTo (p_name, self -> module . imported_definitions[i] . name) &&
@@ -224,32 +254,11 @@ void MCScriptAddImportToModule(MCScriptModuleBuilderRef self, uindex_t p_index,
224254 }
225255 }
226256
227- uindex_t t_imp_index, t_def_index;
228- if (!__extend_array (self, self -> module . imported_definitions, self -> module . imported_definition_count, t_imp_index) ||
229- !__extend_array (self, self -> module . definitions, self -> module . definition_count, t_def_index) ||
230- !MCMemoryNew ((MCScriptExternalDefinition*&)self -> module . definitions[t_def_index]) ||
231- !__append_definition_name (self, p_name))
232- {
233- r_index = 0 ;
234- self -> valid = false ;
235- return ;
236- }
237-
238- MCScriptImportedDefinition *t_import;
239- t_import = &self -> module . imported_definitions[t_imp_index];
240-
241- t_import -> module = p_index;
242- t_import -> kind = p_kind;
243- t_import -> name = MCValueRetain (p_name);
244- // t_import -> type = MCValueRetain(p_type);
245-
246- MCScriptExternalDefinition *t_definition;
247- t_definition = static_cast <MCScriptExternalDefinition *>(self -> module . definitions[t_def_index]);
257+ MCScriptAddDefinitionToModule (self, r_index);
258+ MCScriptAddImportToModuleWithIndex (self, p_index, p_name, p_kind, p_type_index, r_index);
248259
249- t_definition -> kind = kMCScriptDefinitionKindExternal ;
250- t_definition -> index = t_imp_index;
251-
252- r_index = t_def_index;
260+ if (!self -> valid)
261+ r_index = 0 ;
253262}
254263
255264void MCScriptAddDefinitionToModule (MCScriptModuleBuilderRef self, uindex_t & r_index)
0 commit comments