aboutsummaryrefslogtreecommitdiff
path: root/ark/src/world_load.c
diff options
context:
space:
mode:
Diffstat (limited to 'ark/src/world_load.c')
-rw-r--r--ark/src/world_load.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/ark/src/world_load.c b/ark/src/world_load.c
new file mode 100644
index 0000000..098c4b0
--- /dev/null
+++ b/ark/src/world_load.c
@@ -0,0 +1,39 @@
+#include "world.h"
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+#include "world_exports.h"
+
+int load_world_from_dl_(dlhandle_t dl, world_t *world)
+{
+ void *ptr;
+ int ret = 0;
+
+ const char **name = dlsym(dl, "world_name");
+ if (name) {
+ world->world_name = *name;
+ }
+ else {
+ world->world_name = NULL;
+ }
+
+ world->state = NULL;
+ world->library_handle = dl;
+
+#define LOAD_SYM(ret_type, sym, args) \
+ do { \
+ ptr = dlsym(dl, #sym); \
+ if (!ptr) { \
+ fprintf(stderr, "World missing %s\n", #sym); \
+ ret |= 1; \
+ } \
+ world->sym = (ret_type(*) args)ptr; \
+ } while (0);
+
+ ARKWORLD_EXPORTS(LOAD_SYM);
+
+#undef LOAD_SYM
+
+ return ret;
+}