@@ -40,6 +40,7 @@ struct MCRunConfiguration
4040{
4141 MCStringRef m_filename;
4242 MCNameRef m_handler;
43+ MCProperListRef m_load_filenames;
4344 bool m_list_handlers;
4445};
4546
@@ -65,6 +66,7 @@ MCRunUsage (int p_exit_status)
6566" Run a compiled Livecode Builder bytecode file.\n "
6667" \n "
6768" Options:\n "
69+ " -l, --load LCMLIB Load an additional bytecode file.\n "
6870" -H, --handler NAME Specify name of handler to run.\n "
6971" --list-handlers List possible entry points in LCMFILE and exit.\n "
7072" -h, --help Print this message.\n "
@@ -248,6 +250,21 @@ MCRunParseCommandLine (int argc,
248250 continue ;
249251 }
250252
253+ if (MC_RUN_STRING_EQUAL (t_arg, " --load" ) ||
254+ MC_RUN_STRING_EQUAL (t_arg, " -l" ))
255+ {
256+ if (NULL == t_argopt)
257+ MCRunBadOptionArgError (t_arg, t_argopt);
258+
259+ ++t_arg_idx; /* Consume option argument */
260+
261+ /* Add to load list */
262+ if (!MCProperListPushElementOntoFront (x_config.m_load_filenames ,
263+ t_argopt))
264+ return false ;
265+ continue ;
266+ }
267+
251268 if (MC_RUN_STRING_EQUAL (t_arg, " --list-handlers" ))
252269 {
253270 x_config.m_list_handlers = true ;
@@ -327,6 +344,36 @@ MCRunLoadModule (MCStringRef p_filename,
327344 if (!MCScriptCreateModuleFromStream (*t_stream, &t_module))
328345 return false ;
329346
347+ r_module = MCScriptRetainModule (*t_module);
348+ return true ;
349+ }
350+
351+ static bool
352+ MCRunLoadModules (MCStringRef p_filename,
353+ MCProperListRef p_load_filenames,
354+ MCScriptModuleRef & r_module)
355+ {
356+ /* Load main module */
357+ MCAutoScriptModuleRef t_module;
358+ if (!MCRunLoadModule (p_filename, &t_module))
359+ return false ;
360+
361+ /* Load other modules */
362+ MCAutoScriptModuleRefArray t_load_modules;
363+ uindex_t t_num_load = MCProperListGetLength (p_load_filenames);
364+
365+ if (!t_load_modules.New (t_num_load))
366+ return false ;
367+
368+ for (uindex_t i = 0 ; i < t_num_load; ++i)
369+ {
370+ MCValueRef t_element;
371+ t_element = MCProperListFetchElementAtIndex (p_load_filenames, i);
372+ if (!MCRunLoadModule ((MCStringRef) t_element, t_load_modules[i]))
373+ return false ;
374+ }
375+
376+ /* Check main module is usable */
330377 if (!MCScriptEnsureModuleIsUsable (*t_module))
331378 return false ;
332379
@@ -394,6 +441,8 @@ main (int argc,
394441 t_config.m_filename = MCValueRetain (kMCEmptyString );
395442 t_config.m_handler = MCValueRetain (MCNAME (" main" ));
396443 t_config.m_list_handlers = false ;
444+ if (!MCProperListCreateMutable (t_config.m_load_filenames ))
445+ MCRunStartupError (MCSTR (" Initialization" ));
397446
398447 /* ---------- Process command-line arguments */
399448 if (!MCRunParseCommandLine (argc, argv, t_config))
@@ -404,8 +453,10 @@ main (int argc,
404453 MCAutoScriptInstanceRef t_instance;
405454 MCAutoValueRef t_ignored_retval;
406455
407- if (!MCRunLoadModule (t_config.m_filename , &t_module))
408- MCRunStartupError (MCSTR (" Load Module" ));
456+ if (!MCRunLoadModules (t_config.m_filename ,
457+ t_config.m_load_filenames ,
458+ &t_module))
459+ MCRunStartupError (MCSTR (" Load Modules" ));
409460
410461 if (t_config.m_list_handlers )
411462 {
0 commit comments