From bec2d50c843ec4fd98bbbb212848ce4f24b96ebb Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 15 Jun 2024 11:43:10 -0700 Subject: More convenient list iteration. --- plugin/src/plugin.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'plugin') diff --git a/plugin/src/plugin.c b/plugin/src/plugin.c index cd05faf..e2aae1f 100644 --- a/plugin/src/plugin.c +++ b/plugin/src/plugin.c @@ -34,7 +34,7 @@ typedef struct Plugin { mstring filename; } Plugin; -DEF_LIST(Plugin); +DEF_LIST(Plugin, Plugin); /// Plugin engine. typedef struct PluginEngine { @@ -121,7 +121,7 @@ Plugin* load_plugin(PluginEngine* eng, const char* filename) { return 0; } - list_push(eng->plugins, plugin); + list_add(eng->plugins, plugin); return &eng->plugins.head->val; } @@ -180,7 +180,7 @@ void delete_plugin_engine(PluginEngine** pEng) { assert(pEng); PluginEngine* eng = *pEng; if (eng) { - list_foreach_mut(eng->plugins, { destroy_plugin(value); }); + list_foreach_mut(eng->plugins, plugin, { destroy_plugin(&plugin); }); del_list(eng->plugins); if (eng->dir_watch != -1) { inotify_rm_watch(eng->dir_watch, eng->inotify_instance); @@ -226,11 +226,10 @@ void plugin_engine_update(PluginEngine* eng) { if (event->len > 0) { // Name does not include directory, e.g., libfoo.so const mstring file = mstring_make(event->name); - list_foreach_mut(eng->plugins, { - Plugin* plugin = value; - if (mstring_eq(file, plugin_lib_name(plugin))) { - if (load_library(plugin)) { - plugin->reloaded = true; + list_foreach_mut(eng->plugins, plugin, { + if (mstring_eq(file, plugin_lib_name(&plugin))) { + if (load_library(&plugin)) { + plugin.reloaded = true; } break; } -- cgit v1.2.3