From 7411d71fbde5d652f04cc8851ed93bd15513968b Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Thu, 15 Jan 2026 12:11:02 +0000 Subject: Some docs for plugins, among other things. --- src/parser/parser_utils.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/parser/parser_utils.c') diff --git a/src/parser/parser_utils.c b/src/parser/parser_utils.c index 490ea42..2e2fb5b 100644 --- a/src/parser/parser_utils.c +++ b/src/parser/parser_utils.c @@ -1,5 +1,6 @@ #include "../codegen/codegen.h" +#include "../plugins/plugin_manager.h" #include "parser.h" #include #include @@ -2581,8 +2582,40 @@ char *find_similar_symbol(ParserContext *ctx, const char *name) void register_plugin(ParserContext *ctx, const char *name, const char *alias) { + // Try to find existing (built-in) or already loaded plugin + ZPlugin *plugin = zptr_find_plugin(name); + + // If not found, try to load it dynamically + if (!plugin) + { + plugin = zptr_load_plugin(name); + + if (!plugin) + { + char path[1024]; + snprintf(path, sizeof(path), "%s.so", name); + plugin = zptr_load_plugin(path); + } + + if (!plugin && !strchr(name, '/')) + { + char path[1024]; + snprintf(path, sizeof(path), "./%s.so", name); + plugin = zptr_load_plugin(path); + } + } + + if (!plugin) + { + fprintf(stderr, + COLOR_RED "Error:" COLOR_RESET " Could not load plugin '%s'\n" + " Tried built-ins and dynamic loading (.so)\n", + name); + exit(1); + } + ImportedPlugin *p = xmalloc(sizeof(ImportedPlugin)); - p->name = xstrdup(name); + p->name = xstrdup(plugin->name); // Use the plugin's internal name p->alias = alias ? xstrdup(alias) : NULL; p->next = ctx->imported_plugins; ctx->imported_plugins = p; -- cgit v1.2.3