Files

36 lines
1.5 KiB
C

/* prova: blocos .wasm carregam e assinam BlockLike/Renderable. */
#include "catblocks/plugin.h"
#include <stdio.h>
#include <string.h>
int main(void) {
const char *blocks[] = {
"add","subtract","multiply","divide","and","or","not",
"if","else","while","for","when_start"
};
int n = sizeof(blocks)/sizeof(blocks[0]), fail = 0;
printf("%-12s %-8s %-8s %-9s %-5s %s\n", "bloco","BlockLike","Render","cor","cat","nome");
for (int i = 0; i < n; i++) {
char path[128]; snprintf(path, sizeof path, "build/plugins/blocks/%s.wasm", blocks[i]);
char err[256];
cb_plugin *p = cb_plugin_load_file(path, err, sizeof err);
if (!p) { printf("FAIL %s: %s\n", blocks[i], err); fail = 1; continue; }
int bl = cb_plugin_has_blocklike(p);
int rd = cb_plugin_has_renderable(p);
int col = cb_plugin_export_i32(p, "block_color", 0);
int cat = cb_plugin_export_i32(p, "block_cat", 0);
int nl = cb_plugin_export_i32(p, "block_name", 0);
char name[64] = "?";
if (nl > 0 && nl < 63) {
int oa = 0; uint32_t msz = 0;
char *m = cb_plugin_outbuf(p, &oa, &msz);
if (m && oa >= 0 && oa + nl <= (int)msz) { memcpy(name, m + oa, nl); name[nl] = 0; }
}
printf("%-12s %-8d %-8d 0x%06X %-5d %s\n", blocks[i], bl, rd, col, cat, name);
if (!bl) { printf(" AVISO: %s sem BlockLike\n", blocks[i]); fail = 1; }
cb_plugin_free(p);
}
printf(fail ? "BLOCKS: FALHOU\n" : "BLOCKS: OK\n");
return fail;
}