9 #ifdef LOADSO_SDL_VERSION
10 #include "SDL_loadso.h"
11 #elif defined(LOADSO_DLOPEN_VERSION)
15 #ifdef LOADSO_STATIC_VERSION
18 #include "test/game.h"
19 #include "test/menu.h"
20 #include "test/options.h"
22 typedef void (*init_menu_type
)(void *vdata
, struct xuni_t
*xuni
,
23 struct widget_t
*panel
, struct resource_t
*settings
);
25 loadso_t
xuni_loadso_load_object(struct loadso_array_t
*loadso
,
26 const char *filename
) {
28 /* could validate filename here */
33 void xuni_loadso_free_object(loadso_t object
) {
38 static void loadso_add_object(struct loadso_array_t
*loadso
,
39 const char *name
, loadso_t object
);
41 loadso_t
xuni_loadso_load_object(struct loadso_array_t
*loadso
,
42 const char *filename
) {
46 if(!filename
|| !*filename
) return 0;
48 #ifdef LOADSO_SDL_VERSION
49 object
= SDL_LoadObject(filename
);
50 #elif defined(LOADSO_DLOPEN_VERSION)
51 object
= dlopen(filename
, RTLD_LAZY
);
55 #ifdef LOADSO_SDL_VERSION
56 log_message(ERROR_TYPE_WARNING
, ERROR_FLAG_SDL
, __FILE__
, __LINE__
,
57 "Can't load object \"%s\"", filename
);
58 #elif defined(LOADSO_DLOPEN_VERSION)
59 log_message(ERROR_TYPE_WARNING
, 0, __FILE__
, __LINE__
,
60 "Can't load object \"%s\": %s", filename
, dlerror());
63 else loadso_add_object(loadso
, filename
, object
);
68 func_point_t
xuni_loadso_load_function(loadso_t object
, const char *func
) {
71 /* Trying to load a function from a NULL object will fail.
72 No error message is displayed because xuni_loadso_load_object() will
73 have already displayed one.
80 log_message(ERROR_TYPE_WARNING
, 0, __FILE__
, __LINE__
,
81 "Can't load function with NULL or empty name");
85 /* This generates an unavoidable warning, because function pointers
86 cannot be stored in void pointers and vise versa, and dlsym() etc
87 chose to use void pointers for some reason.
89 sofunc
= (func_point_t
)
90 #ifdef LOADSO_SDL_VERSION
91 SDL_LoadFunction(object
, func
);
92 #elif defined(LOADSO_DLOPEN_VERSION)
97 #ifdef LOADSO_SDL_VERSION
98 log_message(ERROR_TYPE_WARNING
, ERROR_FLAG_SDL
, __FILE__
, __LINE__
,
99 "Can't load function \"%s\"", func
);
100 #elif defined(LOADSO_DLOPEN_VERSION)
101 log_message(ERROR_TYPE_WARNING
, 0, __FILE__
, __LINE__
,
102 "Can't load function \"%s\": %s", func
, dlerror());
109 void xuni_loadso_free_object(loadso_t object
) {
110 #ifdef LOADSO_SDL_VERSION
111 SDL_UnloadObject(object
);
112 #elif defined(LOADSO_DLOPEN_VERSION)
117 static void loadso_add_object(struct loadso_array_t
*loadso
,
118 const char *name
, loadso_t object
) {
120 loadso
->object
= xuni_memory_resize(loadso
->object
, (loadso
->objects
+ 1)
121 * sizeof(*loadso
->object
));
122 loadso
->object
[loadso
->objects
].object
= object
;
123 loadso
->object
[loadso
->objects
].name
= xuni_memory_duplicate_string(name
);
129 void init_loadso(struct loadso_array_t
*loadso
) {
134 void free_loadso(struct loadso_array_t
*loadso
) {
137 for(x
= 0; x
< loadso
->objects
; x
++) {
138 xuni_loadso_free_object(loadso
->object
[x
].object
);
139 xuni_memory_free((void *)loadso
->object
[x
].name
);
142 xuni_memory_free(loadso
->object
);
143 xuni_memory_free(loadso
);