From: Javier Sancho Date: Sun, 5 May 2019 18:21:05 +0000 (+0200) Subject: Load mods from selected paths X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=10d6d3bc9bdee3371a2f4dd98701ba77696a0c6d;p=dungeon-master.git Load mods from selected paths --- diff --git a/src/mods.cpp b/src/mods.cpp index bbbd6c4..fb65da3 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "mods.h" @@ -23,12 +24,27 @@ void scm_init_dungeon_master_module() void load_mods() { + scm_init_guile(); + scm_init_dungeon_master_module(); + std::set paths = get_dm_paths(); + DIR* mods_dir; + struct dirent* mod; + std::string + mods_path, + mod_main; + for (const std::string &path : paths) { - std::cout << path << std::endl; + mods_path = path + DIR_DELIM + "mods"; + mods_dir = opendir(mods_path.c_str()); + if (mods_dir != NULL) { + while (mod = readdir(mods_dir)) { + if (strcmp(mod->d_name, ".") != 0 && strcmp(mod->d_name, "..") != 0) { + mod_main = mods_path + DIR_DELIM + mod->d_name + DIR_DELIM + "main.scm"; + scm_primitive_load(scm_from_locale_string(mod_main.c_str())); + } + } + } + closedir(mods_dir); } - - scm_init_guile(); - scm_init_dungeon_master_module(); - scm_primitive_load(scm_from_locale_string("mods/default/main.scm")); }