@@ -229,64 +229,45 @@ void MCEngineLoadExtensionFromData(MCExecContext& ctxt, MCDataRef p_extension_da
229229}
230230
231231// This is the callback given to libscript so that it can resolve the absolute
232- // path of native code libraries used by foreign handlers in the module. At
233- // the moment we use the resources path of the module, however it will need to be
234- // changed to a separate location at some point with explicit declaration so that
235- // iOS linkage and Android placement issues can be resolved.
236- //
237- // Currently it expects:
238- // <resources>
239- // code/
240- // mac/<name>.dylib
241- // linux-x86/<name>.so
242- // linux-x86_64/<name>.so
243- // win-x86/<name>.dll
244- //
232+ // path of native code libraries used by foreign handlers in the module.
233+
245234static bool MCEngineLoadLibrary (MCScriptModuleRef p_module, MCStringRef p_name, MCSLibraryRef& r_library)
246235{
247- // If the module has no resource path, then it has no code.
248- MCAutoStringRef t_resource_path;
249- if (!MCEngineLookupResourcePathForModule (p_module, Out (t_resource_path)))
250- return false ;
251-
252236 MCSLibraryRef t_library = nullptr ;
253- if (t_resource_path.IsSet () &&
254- !MCStringIsEmpty (*t_resource_path))
237+
238+ // extension libraries should be mapped by the IDE or deploy params
239+ MCAutoStringRef t_mapped_path;
240+ if (MCdispatcher->fetchlibrarymapping (p_name, &t_mapped_path))
255241 {
256- #if defined(__MAC__)
257- static const char *kLibraryFormat = " %@/code/mac/%@" ;
258- #elif defined(__LINUX__) && defined(__32_BIT__)
259- static const char *kLibraryFormat = " %@/code/linux-x86/%@" ;
260- #elif defined(__LINUX__) && defined(__64_BIT__)
261- static const char *kLibraryFormat = " %@/code/linux-x86_64/%@" ;
262- #elif defined(__WINDOWS__)
263- static const char *kLibraryFormat = " %@/code/win-x86/%@" ;
264- #elif defined(__ANDROID__)
265- static const char *kLibraryFormat = " %@/code/android-armv6/%@" ;
266- #elif defined(__IOS__)
267- static const char *kLibraryFormat = " %@/code/ios/%@" ;
268- #elif defined(__EMSCRIPTEN__)
269- static const char *kLibraryFormat = " %@/code/emscripten/%@" ;
270- #else
271- #error No default code path set for this platform
272- #endif
273- MCAutoStringRef t_ext_path;
274- if (!MCStringFormat (&t_ext_path,
275- kLibraryFormat ,
276- *t_resource_path,
277- p_name))
242+ MCAutoStringRef t_map_name;
243+ if (!MCStringFormat (&t_map_name, " ./%@" , p_name))
244+ return false ;
245+
246+ t_library = MCU_library_load (*t_map_name);
247+
248+ // there was a mapping and it failed to load
249+ if (t_library == nullptr )
278250 {
279251 return false ;
280252 }
281-
282- t_library = MCU_library_load (*t_ext_path);
283253 }
284254
255+ // if not mapped then fallback to assuming a full path or a location
256+ // supported by dlopen
285257 if (t_library == nullptr )
286258 {
287259 t_library = MCU_library_load (p_name);
288260 }
289261
262+ #if defined(__IOS__)
263+ // On iOS we fallback to the engine because with the exception of
264+ // dynamic frameworks libraries will be static linked
265+ if (t_library == nullptr )
266+ {
267+ t_library = MCValueRetain (MCScriptGetLibrary ());
268+ }
269+ #endif
270+
290271 if (t_library == nullptr )
291272 {
292273 return false ;
0 commit comments