paint: merge gc remove

This commit is contained in:
luboslenco
2026-08-21 22:35:41 +02:00
parent 4c77755da0
commit eb25ff4f46
213 changed files with 3104 additions and 2920 deletions
+14 -6
View File
@@ -4,26 +4,34 @@
char *_plugin_name;
plugin_t *plugin_create() {
plugin_t *p = GC_ALLOC_INIT(plugin_t, {0});
plugin_t *p = ALLOC_INIT(plugin_t, {0});
p->name = string_copy(_plugin_name);
any_map_set(g_plugins, p->name, p);
return p;
}
void plugin_start(char *plugin) {
buffer_t *blob = data_get_blob(string("plugins/%s", plugin));
gc_unroot(_plugin_name);
char *file = string("plugins/%s", plugin);
buffer_t *blob = data_get_blob(file);
if (blob == NULL) {
return;
}
_plugin_name = string_copy(plugin);
gc_root(_plugin_name);
minic_ctx_t *ctx = minic_eval_named(sys_buffer_to_string(blob), plugin);
data_delete_blob(string("plugins/%s", plugin));
data_delete_blob(file);
// Store context on the plugin so callbacks can use it and it can be freed on stop
plugin_t *p = any_map_get(g_plugins, plugin);
p->ctx = ctx;
if (p == NULL) { // Script did not call plugin_create()
p = plugin_create();
}
p->ctx = ctx;
}
void plugin_stop(char *plugin) {
plugin_t *p = any_map_get(g_plugins, plugin);
if (p == NULL) {
return;
}
if (p->on_delete != NULL) {
minic_ctx_call_fn(p->ctx, p->on_delete, NULL, 0);
}