@@ -64,6 +64,7 @@ static void *plugin_extension_handle = NULL;
6464
6565/* -- Private Methods -- */
6666
67+ static int metacall_plugin_extension_load (void );
6768static void * metacallv_method (void * target , const char * name , method_invoke_ptr call , vector v , void * args [], size_t size );
6869static type_id * metacall_type_ids (void * args [], size_t size );
6970
@@ -86,12 +87,57 @@ void metacall_flags(int flags)
8687 metacall_config_flags = flags ;
8788}
8889
89- int metacall_initialize (void )
90+ int metacall_plugin_extension_load (void )
9091{
9192 static const char * ext_scripts [] = {
9293 "plugin_extension"
9394 };
95+ static const char plugin_suffix [] = "plugins" ;
96+ const char * library_path = loader_library_path ();
97+ loader_path plugin_path ;
98+ size_t plugin_path_size ;
99+ void * args [2 ];
100+ void * ret ;
101+ int result = 1 ;
102+
103+ /* Load the plugin extension */
104+ if (metacall_load_from_file ("ext" , ext_scripts , sizeof (ext_scripts ) / sizeof (ext_scripts [0 ]), & plugin_extension_handle ) != 0 )
105+ {
106+ goto plugin_extension_error ;
107+ }
108+
109+ /* Get the plugin path */
110+ plugin_path_size = portability_path_join (library_path , strnlen (library_path , PORTABILITY_PATH_SIZE ) + 1 , plugin_suffix , sizeof (plugin_suffix ), plugin_path , PORTABILITY_PATH_SIZE );
111+
112+ /* Load core plugins into plugin extension handle */
113+ args [0 ] = metacall_value_create_string (plugin_path , plugin_path_size - 1 );
114+ args [1 ] = metacall_value_create_ptr (& plugin_extension_handle );
115+ ret = metacallhv_s (plugin_extension_handle , "plugin_load_from_path" , args , sizeof (args ) / sizeof (args [0 ]));
94116
117+ if (ret == NULL )
118+ {
119+ goto plugin_load_from_path_error ;
120+ }
121+
122+ if (metacall_value_id (ret ) != METACALL_INT )
123+ {
124+ goto plugin_load_from_path_type_error ;
125+ }
126+
127+ /* Retrieve the result value */
128+ result = metacall_value_to_int (ret );
129+
130+ plugin_load_from_path_type_error :
131+ metacall_value_destroy (ret );
132+ plugin_load_from_path_error :
133+ metacall_value_destroy (args [0 ]);
134+ metacall_value_destroy (args [1 ]);
135+ plugin_extension_error :
136+ return result ;
137+ }
138+
139+ int metacall_initialize (void )
140+ {
95141 memory_allocator allocator ;
96142
97143 /* Initialize logs by default to stdout if none has been defined */
@@ -193,16 +239,11 @@ int metacall_initialize(void)
193239 return 1 ;
194240 }
195241
196- /* Load plugin extension */
197- if (metacall_load_from_file ( "ext" , ext_scripts , sizeof ( ext_scripts ) / sizeof ( ext_scripts [ 0 ]), & plugin_extension_handle ) != 0 )
242+ /* Load core plugins */
243+ if (metacall_plugin_extension_load ( ) != 0 )
198244 {
199245 log_write ("metacall" , LOG_LEVEL_WARNING , "MetaCall Plugin Extension could not be loaded" );
200246 }
201- else
202- {
203- /* TODO: Load core extensions */
204- /* ... */
205- }
206247
207248 metacall_initialize_flag = 0 ;
208249
0 commit comments