tinyblocks-api (gestor publico de modulos/libraries): - registry de modulos (embutidos + .so), load/unload/reload via dlopen, hot reload por mtime e introspeccao de tipos de bloco. - substitui a logica de hotlib duplicada no editor. tinyblocks-libman (gestor/buscador de libraries): - varre library.toml (libraries/ e ~/.tinyblocks/libraries), le metadados de forma RECURSIVA e resolve o caminho do .so/.a. - busca por texto e filtro por categoria; consulta o estado de carga na api. Editor: tela cheia "Escolha uma Extensão" (UI desenhada pelo editor, como no Scratch): botao Bibliotecas / Ctrl+L, busca, chips de categoria que quebram linha, grade de cartoes com faixa colorida e selo "carregada"; clicar carrega o .so via api. Respeito a interfaces publicas entre libraries: - libman deixa de incluir o ast.h (interno) do tinyblocks-toml e passa a usar uma API publica e opaca: tb_toml_open/close/str/int/int_array. - core ganha accessors publicos: tb_rt_type_count/at, tb_rt_library_count/at, tb_library_name/category/block_count; api e editor usam-nos em vez de ler campos de struct do core diretamente. Testes: make test-libman (novo) + step no harness que abre o libman, busca, carrega um .so e confirma a categoria na paleta. test-editor/toml/blueprint/ plugin seguem OK.
84 lines
3.2 KiB
C
84 lines
3.2 KiB
C
/*
|
|
* libman_test.c - testa tinyblocks-libman + tinyblocks-api:
|
|
* varredura de library.toml, leitura de metadados, busca, categorias,
|
|
* estado de carga e introspeccao de tipos.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <tinyblocks/tinyblocks.h>
|
|
#include <tb_api.h>
|
|
#include <tb_libman.h>
|
|
#include <tb_events.h>
|
|
#include <tb_control.h>
|
|
#include <tb_operators.h>
|
|
#include <tb_variables.h>
|
|
#include <tb_appearance.h>
|
|
#include <tb_pen.h>
|
|
#include <tb_fs.h>
|
|
#include <tb_toml.h>
|
|
|
|
static int fails = 0;
|
|
#define CHECK(c, m) do { if (c) printf("ok %s\n", m); else { printf("FAIL %s\n", m); fails++; } } while (0)
|
|
|
|
int main(void) {
|
|
TinyBlocks* rt;
|
|
tinyblocks_init(&rt, NULL);
|
|
tb_library_register(rt, tb_events_get_library());
|
|
tb_library_register(rt, tb_control_get_library());
|
|
tb_library_register(rt, tb_operators_get_library());
|
|
tb_library_register(rt, tb_variables_get_library());
|
|
tb_library_register(rt, tb_appearance_get_library());
|
|
tb_library_register(rt, tb_pen_get_library());
|
|
tb_library_register(rt, tb_fs_get_library());
|
|
tb_library_register(rt, tb_toml_get_library());
|
|
|
|
CHECK(tb_libman_init(rt), "libman init (liga a api)");
|
|
|
|
int n = tb_libman_scan_defaults();
|
|
printf(" libraries encontradas: %d (%d novas)\n", tb_libman_count(), n);
|
|
CHECK(tb_libman_count() >= 12, "varredura encontra as libraries do repo");
|
|
|
|
int ev = -1, tm = -1, bp = -1;
|
|
for (int i = 0; i < tb_libman_count(); i++) {
|
|
const TbLibmanEntry* e = tb_libman_entry(i);
|
|
if (strcmp(e->name, "tinyblocks-events") == 0) ev = i;
|
|
if (strcmp(e->name, "tinyblocks-toml") == 0) tm = i;
|
|
if (strcmp(e->name, "tinyblocks-blueprint") == 0) bp = i;
|
|
}
|
|
CHECK(ev >= 0, "encontra tinyblocks-events");
|
|
CHECK(tm >= 0, "encontra tinyblocks-toml");
|
|
CHECK(bp >= 0, "encontra tinyblocks-blueprint");
|
|
|
|
if (ev >= 0) {
|
|
const TbLibmanEntry* e = tb_libman_entry(ev);
|
|
CHECK(strcmp(e->category, "Eventos") == 0, "categoria lida do .toml");
|
|
CHECK(strstr(e->shared, ".so") != NULL, "caminho do .so resolvido");
|
|
CHECK(e->color[0] == 255 && e->color[1] == 191 && e->color[2] == 0,
|
|
"cor lida do array .toml");
|
|
CHECK(tb_libman_loaded(ev), "events embutida consta como carregada");
|
|
}
|
|
if (bp >= 0)
|
|
CHECK(!tb_libman_loaded(bp), "blueprint (nao registrada) consta como nao carregada");
|
|
|
|
int hits[TBLM_MAX_ENTRIES];
|
|
int h = tb_libman_search("toml", "", hits, TBLM_MAX_ENTRIES);
|
|
CHECK(h >= 1, "busca por 'toml' retorna resultado");
|
|
h = tb_libman_search("", "Eventos", hits, TBLM_MAX_ENTRIES);
|
|
CHECK(h == 1, "filtro por categoria Eventos retorna 1");
|
|
|
|
char cats[32][48];
|
|
int cn = tb_libman_categories(cats, 32);
|
|
int has_ev = 0;
|
|
for (int i = 0; i < cn; i++) if (strcmp(cats[i], "Eventos") == 0) has_ev = 1;
|
|
CHECK(cn >= 5 && has_ev, "categorias distintas incluem Eventos");
|
|
|
|
/* tinyblocks-api: introspeccao de tipos */
|
|
CHECK(tb_api_type_find("Events.WhenRun") != NULL, "api encontra Events.WhenRun");
|
|
CHECK(tb_api_type_count() > 10, "api enumera os tipos registrados");
|
|
|
|
tb_libman_shutdown();
|
|
tinyblocks_deinit(&rt);
|
|
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
|
return fails != 0;
|
|
}
|