Update lua.c

Allowed Lua scripts to be located by basename (script name only) when resolving /lua unload and related operations, while keeping path-based matching for explicit paths.
Ensured /lua load reports failures when script creation fails and added explicit failure feedback to the user.
Added unload feedback that distinguishes immediate unloads from deferred unloads, so users see confirmation right away.
This commit is contained in:
deepend-tildeclub
2026-01-25 16:02:58 -07:00
committed by GitHub
parent 4e01192979
commit 4ed7032fd5

View File

@@ -1370,15 +1370,28 @@ static script_info *create_script(char const *file)
static script_info *get_script_by_file(char const *filename) static script_info *get_script_by_file(char const *filename)
{ {
char const *expanded = expand_path(filename);
guint i; guint i;
for(i = 0; i < scripts->len; i++) for(i = 0; i < scripts->len; i++)
{ {
script_info *script = scripts->pdata[i]; script_info *script = scripts->pdata[i];
if(!strcmp(script->filename, expanded)) if(!strcmp(script->filename, filename))
{ {
return script; return script;
} }
if(g_path_is_absolute(filename) || strchr(filename, '/'))
{
char const *expanded = expand_path(filename);
if(!strcmp(script->filename, expanded))
return script;
}
else
{
char *basename = g_path_get_basename(script->filename);
gboolean match = !strcmp(basename, filename);
g_free(basename);
if(match)
return script;
}
} }
return NULL; return NULL;
@@ -1395,11 +1408,13 @@ static int load_script(char const *file)
} }
info = create_script(file); info = create_script(file);
if (info) if (!info)
{ {
return 0;
}
g_ptr_array_add(scripts, info); g_ptr_array_add(scripts, info);
check_deferred(info); check_deferred(info);
}
return 1; return 1;
} }
@@ -1629,11 +1644,24 @@ static int command_lua(char *word[], char *word_eol[], void *userdata)
{ {
if(!strcmp(word[2], "load")) if(!strcmp(word[2], "load"))
{ {
load_script(word[3]); if(load_script(word[3]))
zoitechat_printf(ph, "Loaded Lua script '%s'", word[3]);
else
zoitechat_printf(ph, "Failed to load Lua script '%s'", word[3]);
} }
else if(!strcmp(word[2], "unload")) else if(!strcmp(word[2], "unload"))
{ {
if(!unload_script(word[3])) script_info *script = get_script_by_file(word[3]);
if(script)
{
gboolean deferred = script->status & STATUS_ACTIVE;
unload_script(word[3]);
if(deferred)
zoitechat_printf(ph, "Unload scheduled for Lua script '%s'", word[3]);
else
zoitechat_printf(ph, "Unloaded Lua script '%s'", word[3]);
}
else
zoitechat_printf(ph, "Could not find a script by the name '%s'", word[3]); zoitechat_printf(ph, "Could not find a script by the name '%s'", word[3]);
} }
else if(!strcmp(word[2], "reload")) else if(!strcmp(word[2], "reload"))
@@ -1689,7 +1717,7 @@ static int command_lua(char *word[], char *word_eol[], void *userdata)
g_free(basename); g_free(basename);
} }
if(interp) if(interp)
zoitechat_printf(ph, "%-16s %-8s", interp->name, plugin_version); zoitechat_printf(ph, "%-16s %-8s %-20s %-10s", interp->name, plugin_version, "", "");
} }
else if(!strcmp(word[2], "console")) else if(!strcmp(word[2], "console"))
{ {