Converte símbolos Unicode decorativos dos comentários para ASCII

Substitui barras de caixa (─ ═ │ ┌ ┐ └ ┘ ├ ┤ ┬ ┴), travessões (—),
setas (→ ←), reticências (…), bullets (•), multiplicação (×) e
guillemets (› ‹) por equivalentes ASCII. Acentos portugueses são
preservados.
This commit is contained in:
mguinhos committed 2026-10-20 19:27:33 -03:00
1 parent 1cc0ff9d02
commit 90d47bf8a0
36 files changed
+327 -327

No files matched your search

+19 -19
View File
@@ -1,13 +1,13 @@
/*
* customappearance.c — Demonstração de on_draw (aparência personalizada de bloco).
* customappearance.c - Demonstração de on_draw (aparência personalizada de bloco).
*
* Blocos:
* Viz.ColorSwatch — inputs: r, g, b, a (0..1) → mostra quadrado colorido
* Viz.Gauge — inputs: value (0..1), r, g, b → barra de progresso
* Viz.Star — inputs: r, g, b, a → estrela de 5 pontas (contorno)
* Viz.BarChart — inputs: a, b, c, d (reais) → mini gráfico de barras
* Viz.ColorSwatch - inputs: r, g, b, a (0..1) -> mostra quadrado colorido
* Viz.Gauge - inputs: value (0..1), r, g, b -> barra de progresso
* Viz.Star - inputs: r, g, b, a -> estrela de 5 pontas (contorno)
* Viz.BarChart - inputs: a, b, c, d (reais) -> mini gráfico de barras
*
* make customappearance → build/customappearance.so
* make customappearance -> build/customappearance.so
*/
#define _POSIX_C_SOURCE 200809L
@@ -16,7 +16,7 @@
#include <tinyblocks/tinyblocks.h>
#include <tinyblocks/tb_renderable_block.h>
/* ── Helpers ─────────────────────────────────────────────────────────────── */
/* -- Helpers --- */
static float gf(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t idx) {
TinyBlocks_Value v = tb_block_get_input(self, rt, idx);
if (v.kind == TB_VALUE_REAL) return (float)v.as.real;
@@ -32,9 +32,9 @@ static float out_f(TinyBlocks_Block* self, uint32_t idx) {
return 0.0f;
}
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Viz.ColorSwatch
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static void eval_color_swatch(TinyBlocks_Block* self, TinyBlocks* rt) {
for (uint32_t i = 0; i < 4 && i < self->output_count; i++)
tb_block_set_output(self, i, tb_value_real((double)gf(self, rt, i)));
@@ -76,9 +76,9 @@ static bool draw_color_swatch(TinyBlocks_Block* self, TinyBlocks* rt,
return true;
}
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Viz.Gauge
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static void eval_gauge(TinyBlocks_Block* self, TinyBlocks* rt) {
for (uint32_t i = 0; i < 4 && i < self->output_count; i++)
tb_block_set_output(self, i, tb_value_real((double)gf(self, rt, i)));
@@ -116,9 +116,9 @@ static bool draw_gauge(TinyBlocks_Block* self, TinyBlocks* rt,
return true;
}
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Viz.Star
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static void eval_star(TinyBlocks_Block* self, TinyBlocks* rt) {
for (uint32_t i = 0; i < 4 && i < self->output_count; i++)
tb_block_set_output(self, i, tb_value_real((double)gf(self, rt, i)));
@@ -166,9 +166,9 @@ static bool draw_star(TinyBlocks_Block* self, TinyBlocks* rt,
return true;
}
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Viz.BarChart
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static void eval_barchart(TinyBlocks_Block* self, TinyBlocks* rt) {
for (uint32_t i = 0; i < 4 && i < self->output_count; i++)
tb_block_set_output(self, i, tb_value_real((double)gf(self, rt, i)));
@@ -218,9 +218,9 @@ static bool draw_barchart(TinyBlocks_Block* self, TinyBlocks* rt,
return true;
}
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Descritores de slots
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static const TinyBlocks_SlotDesc rgba_in[] = {
{"r", TB_VALUE_REAL}, {"g", TB_VALUE_REAL},
{"b", TB_VALUE_REAL}, {"a", TB_VALUE_REAL}
@@ -246,9 +246,9 @@ static const TinyBlocks_SlotDesc chart_out[] = {
{"c", TB_VALUE_REAL}, {"d", TB_VALUE_REAL}
};
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Registro
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static bool ca_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
TinyBlocks_TypeBlock* t;
+18 -18
View File
@@ -1,5 +1,5 @@
/*
* TinyBlocks — exemplo hello
* TinyBlocks - exemplo hello
*
* Demonstra:
* 1. Inicializar o runtime
@@ -11,7 +11,7 @@
#include <stdio.h>
#include <tinyblocks/tinyblocks.h>
/* ── TypeBlock: Math.Add ─────────────────────────────────────────────────── */
/* -- TypeBlock: Math.Add --- */
/* inputs: a(int), b(int)
* outputs: result(int) */
static void eval_math_add(TinyBlocks_Block* self, TinyBlocks* rt)
@@ -23,7 +23,7 @@ static void eval_math_add(TinyBlocks_Block* self, TinyBlocks* rt)
tb_block_set_output(self, 0, tb_value_integer(a + b));
}
/* ── TypeBlock: Math.Mul ─────────────────────────────────────────────────── */
/* -- TypeBlock: Math.Mul --- */
static void eval_math_mul(TinyBlocks_Block* self, TinyBlocks* rt)
{
TinyBlocks_Value va = tb_block_get_input(self, rt, 0);
@@ -33,7 +33,7 @@ static void eval_math_mul(TinyBlocks_Block* self, TinyBlocks* rt)
tb_block_set_output(self, 0, tb_value_integer(a * b));
}
/* ── TypeBlock: IO.Print ─────────────────────────────────────────────────── */
/* -- TypeBlock: IO.Print --- */
/* inputs: label(text), value(int)
* outputs: (nenhum) */
static void eval_io_print(TinyBlocks_Block* self, TinyBlocks* rt)
@@ -54,7 +54,7 @@ static void eval_io_print(TinyBlocks_Block* self, TinyBlocks* rt)
printf("[IO.Print] %s = %s\n", label, valstr);
}
/* ── TypeBlock: Math.Factorial (demonstra userdata por instância) ─────────── */
/* -- TypeBlock: Math.Factorial (demonstra userdata por instância) --- */
/* inputs: n(int)
* outputs: result(int) */
typedef struct { int64_t memo; } FactorialData;
@@ -72,12 +72,12 @@ static void eval_math_factorial(TinyBlocks_Block* self, TinyBlocks* rt)
tb_block_set_output(self, 0, tb_value_integer(result));
}
/* ═══════════════════════════════════════════════════════════════════════════
/* ===
* main
* ═══════════════════════════════════════════════════════════════════════════ */
* === */
int main(void)
{
printf("=== TinyBlocks — exemplo hello ===\n\n");
printf("=== TinyBlocks - exemplo hello ===\n\n");
/* 1. Inicializar runtime */
TinyBlocks* rt = NULL;
@@ -124,7 +124,7 @@ int main(void)
printf("[libs] Math=%u blocos, IO=%u bloco(s)\n\n",
lib_math->block_count, lib_io->block_count);
/* ── Exemplo 1: 3 + 4 ───────────────────────────────────────────────── */
/* -- Exemplo 1: 3 + 4 --- */
printf("--- Exemplo 1: 3 + 4 ---\n");
{
TinyBlocks_IntegerBlock* lit3 = tb_integer_block_create(rt, 3);
@@ -133,13 +133,13 @@ int main(void)
TinyBlocks_Block* add = tb_block_create(rt, t_add);
TinyBlocks_Block* print = tb_block_create(rt, t_print);
/* Conecta: add.in[0] ← lit3.out[0]
add.in[1] ← lit4.out[0] */
/* Conecta: add.in[0] <- lit3.out[0]
add.in[1] <- lit4.out[0] */
tb_block_connect(add, 0, &lit3->base, 0);
tb_block_connect(add, 1, &lit4->base, 0);
/* print.in[0] ← label.out[0]
print.in[1] ← add.out[0] */
/* print.in[0] <- label.out[0]
print.in[1] <- add.out[0] */
tb_block_connect(print, 0, &label->base, 0);
tb_block_connect(print, 1, add, 0);
@@ -147,7 +147,7 @@ int main(void)
tb_block_eval(print, rt);
}
/* ── Exemplo 2: (2 + 3) * 5 ────────────────────────────────────────── */
/* -- Exemplo 2: (2 + 3) * 5 --- */
printf("\n--- Exemplo 2: (2 + 3) * 5 ---\n");
{
TinyBlocks_IntegerBlock* lit2 = tb_integer_block_create(rt, 2);
@@ -168,7 +168,7 @@ int main(void)
tb_block_eval(print, rt);
}
/* ── Exemplo 3: 7! (fatorial com userdata por instância) ────────────── */
/* -- Exemplo 3: 7! (fatorial com userdata por instância) --- */
printf("\n--- Exemplo 3: 7! ---\n");
{
TinyBlocks_IntegerBlock* lit7 = tb_integer_block_create(rt, 7);
@@ -187,7 +187,7 @@ int main(void)
printf(" userdata.memo = %lld\n", (long long)d->memo);
}
/* ── Exemplo 4: busca de tipo por nome ──────────────────────────────── */
/* -- Exemplo 4: busca de tipo por nome --- */
printf("\n--- Exemplo 4: busca de tipo por nome ---\n");
{
TinyBlocks_TypeBlock* found = tb_type_block_find(rt, "Math.Add");
@@ -202,7 +202,7 @@ int main(void)
? ((TinyBlocks_TypeBlock*)b)->type_name : "?");
}
/* ── Exemplo 5: to_string ────────────────────────────────────────────── */
/* -- Exemplo 5: to_string --- */
printf("\n--- Exemplo 5: representação textual ---\n");
{
TinyBlocks_IntegerBlock* ib = tb_integer_block_create(rt, 42);
@@ -222,7 +222,7 @@ int main(void)
printf("TextBlock: %s\n", buf);
}
/* ── Resumo do runtime ───────────────────────────────────────────────── */
/* -- Resumo do runtime --- */
printf("\n--- Estado do runtime ---\n");
printf("blocks vivos: %u\n", rt->block_count);
printf("types: %u\n", rt->type_count);
+26 -26
View File
@@ -1,24 +1,24 @@
/*
* json.c — Library de JSON para o TinyBlocks Editor.
* json.c - Library de JSON para o TinyBlocks Editor.
*
* Blocos incluídos:
* Json.Parse — texto -> json (null em caso de erro de sintaxe)
* Json.Stringify — json -> texto
* Json.Null — constrói json null
* Json.Bool — inteiro (0/1) -> json bool
* Json.Number — real -> json number
* Json.String — texto -> json string
* Json.Array — constrói array vazio
* Json.Object — constrói objeto vazio
* Json.Push — (array, valor) -> novo array com valor anexado
* Json.Set — (objeto, chave, valor) -> novo objeto com campo definido
* Json.Get — (objeto, chave) -> valor do campo, ou Json.Null
* Json.Index — (array, índice) -> valor na posição, ou Json.Null
* Json.Length — (json) -> nº de elementos (array/objeto) ou 0
* Json.TypeOf — (json) -> "null"|"bool"|"number"|"string"|"array"|"object"
* Json.ToNumber — (json, default) -> número (ou default se não for number/bool)
* Json.ToText — (json) -> string contida, ou "" se não for string
* Json.ToBool — (json, default) -> 0/1 (ou default se não for bool/number)
* Json.Parse - texto -> json (null em caso de erro de sintaxe)
* Json.Stringify - json -> texto
* Json.Null - constrói json null
* Json.Bool - inteiro (0/1) -> json bool
* Json.Number - real -> json number
* Json.String - texto -> json string
* Json.Array - constrói array vazio
* Json.Object - constrói objeto vazio
* Json.Push - (array, valor) -> novo array com valor anexado
* Json.Set - (objeto, chave, valor) -> novo objeto com campo definido
* Json.Get - (objeto, chave) -> valor do campo, ou Json.Null
* Json.Index - (array, índice) -> valor na posição, ou Json.Null
* Json.Length - (json) -> nº de elementos (array/objeto) ou 0
* Json.TypeOf - (json) -> "null"|"bool"|"number"|"string"|"array"|"object"
* Json.ToNumber - (json, default) -> número (ou default se não for number/bool)
* Json.ToText - (json) -> string contida, ou "" se não for string
* Json.ToBool - (json, default) -> 0/1 (ou default se não for bool/number)
*
* Json.Push/Json.Set não mutam o valor recebido: clonam e devolvem uma nova
* árvore, mantendo o fluxo de dados imutável como o resto do TinyBlocks.
@@ -27,7 +27,7 @@
* make json
*
* Para carregar no editor:
* Ctrl+O → build/json.so ou arraste build/json.so para a janela
* Ctrl+O -> build/json.so ou arraste build/json.so para a janela
*/
#define _POSIX_C_SOURCE 200809L
@@ -36,7 +36,7 @@
#include <tinyblocks/tinyblocks.h>
/* ── Helpers de leitura de inputs ────────────────────────────────────────── */
/* -- Helpers de leitura de inputs --- */
static const char* gt(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t idx) {
TinyBlocks_Value v = tb_block_get_input(self, rt, idx);
return v.kind == TB_VALUE_TEXT ? v.as.text : "";
@@ -68,9 +68,9 @@ static TinyBlocks_JsonValue* gj(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t
(self)->dirty = false; \
} while (0)
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Implementações dos blocos
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static void eval_parse(TinyBlocks_Block* self, TinyBlocks* rt) {
char err[128] = {0};
@@ -191,9 +191,9 @@ static void eval_to_bool(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false;
}
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Descritores de slots
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static const TinyBlocks_SlotDesc out_json[] = {{"json", TB_VALUE_JSON}};
static const TinyBlocks_SlotDesc out_text[] = {{"text", TB_VALUE_TEXT}};
static const TinyBlocks_SlotDesc out_integer[] = {{"n", TB_VALUE_INTEGER}};
@@ -217,9 +217,9 @@ static const TinyBlocks_SlotDesc in_json_real[] = {{"json", TB_VALUE_JSON},
static const TinyBlocks_SlotDesc in_json_int_def[] = {{"json", TB_VALUE_JSON},
{"def", TB_VALUE_INTEGER}};
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Registro da library
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static bool json_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
TinyBlocks_TypeBlock* t;
+13 -13
View File
@@ -1,29 +1,29 @@
/*
* mcp.c — Plugin TinyBlocks com blocos MCP (Model Context Protocol).
* mcp.c - Plugin TinyBlocks com blocos MCP (Model Context Protocol).
*
* Blocos:
* MCP.Server — literal: armazena a URL do servidor MCP
* MCP.Server - literal: armazena a URL do servidor MCP
* HTTP: "http://localhost:3000/mcp"
* stdio: "stdio://npx @modelcontextprotocol/server-filesystem /tmp"
*
* MCP.Ping — input: url (text) → output: status (text)
* MCP.Ping - input: url (text) -> output: status (text)
* Verifica se o servidor responde.
*
* MCP.ListTools — input: url (text) → output: tools (text)
* MCP.ListTools - input: url (text) -> output: tools (text)
* Lista ferramentas disponíveis no servidor.
*
* MCP.Call — inputs: url, tool, args (text) → output: result (text)
* MCP.Call - inputs: url, tool, args (text) -> output: result (text)
* Chama uma ferramenta com argumentos JSON.
*
* Compilar:
* make mcp-lib
*
* Carregar no editor:
* ./build/editor build/mcp.so ou Ctrl+O → build/mcp.so
* ./build/editor build/mcp.so ou Ctrl+O -> build/mcp.so
*
* Exemplo de uso no editor:
* [Literal.Text "stdio://npx @modelcontextprotocol/server-filesystem /tmp"]
* → [MCP.ListTools] → [IO.Print "tools"]
* -> [MCP.ListTools] -> [IO.Print "tools"]
*/
#define _POSIX_C_SOURCE 200809L
@@ -32,13 +32,13 @@
#include <tinyblocks/tinyblocks.h>
#include <tinyblocks-mcp/tb_mcp.h>
/* ── Helper: lê texto de slot ────────────────────────────────────────────── */
/* -- Helper: lê texto de slot --- */
static const char* gs(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t idx) {
TinyBlocks_Value v = tb_block_get_input(self, rt, idx);
return (v.kind == TB_VALUE_TEXT && v.as.text) ? v.as.text : "";
}
/* ── MCP.Ping ────────────────────────────────────────────────────────────── */
/* -- MCP.Ping --- */
static void eval_mcp_ping(TinyBlocks_Block* self, TinyBlocks* rt) {
const char* url = gs(self, rt, 0);
char* result = tb_mcp_ping(url);
@@ -47,7 +47,7 @@ static void eval_mcp_ping(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false;
}
/* ── MCP.ListTools ───────────────────────────────────────────────────────── */
/* -- MCP.ListTools --- */
static void eval_mcp_list_tools(TinyBlocks_Block* self, TinyBlocks* rt) {
const char* url = gs(self, rt, 0);
char* result = tb_mcp_list_tools(url);
@@ -56,7 +56,7 @@ static void eval_mcp_list_tools(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false;
}
/* ── MCP.Call ────────────────────────────────────────────────────────────── */
/* -- MCP.Call --- */
static void eval_mcp_call(TinyBlocks_Block* self, TinyBlocks* rt) {
const char* url = gs(self, rt, 0);
const char* tool = gs(self, rt, 1);
@@ -67,7 +67,7 @@ static void eval_mcp_call(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false;
}
/* ── Slots ───────────────────────────────────────────────────────────────── */
/* -- Slots --- */
static const TinyBlocks_SlotDesc url_in[] = {{"url", TB_VALUE_TEXT}};
static const TinyBlocks_SlotDesc call_in[] = {{"url", TB_VALUE_TEXT},
{"tool", TB_VALUE_TEXT},
@@ -76,7 +76,7 @@ static const TinyBlocks_SlotDesc status_out[] = {{"status", TB_VALUE_TEXT}};
static const TinyBlocks_SlotDesc tools_out[] = {{"tools", TB_VALUE_TEXT}};
static const TinyBlocks_SlotDesc result_out[] = {{"result", TB_VALUE_TEXT}};
/* ── Registro ────────────────────────────────────────────────────────────── */
/* -- Registro --- */
static bool mcp_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
if (!tb_mcp_init()) return false;
+12 -12
View File
@@ -1,20 +1,20 @@
/*
* mylib.c — Library de exemplo para testar hot reload no TinyBlocks Editor.
* mylib.c - Library de exemplo para testar hot reload no TinyBlocks Editor.
*
* Blocos incluídos:
* Extra.Square — n² de um inteiro
* Extra.Cube — n³ de um inteiro
* Extra.Clamp — limita valor entre min e max
* Extra.Fibonacci — n-ésimo número de Fibonacci
* Extra.IsEven — 1 se par, 0 se ímpar
* Extra.IntToText — converte inteiro em texto
* Extra.Pow — base elevado a exp (inteiros)
* Extra.Square - n^2 de um inteiro
* Extra.Cube - n^3 de um inteiro
* Extra.Clamp - limita valor entre min e max
* Extra.Fibonacci - n-ésimo número de Fibonacci
* Extra.IsEven - 1 se par, 0 se ímpar
* Extra.IntToText - converte inteiro em texto
* Extra.Pow - base elevado a exp (inteiros)
*
* Para compilar:
* make mylib
*
* Para carregar no editor:
* Ctrl+O → build/mylib.so ou arraste build/mylib.so para a janela
* Ctrl+O -> build/mylib.so ou arraste build/mylib.so para a janela
*/
#define _POSIX_C_SOURCE 200809L
@@ -24,7 +24,7 @@
#include <tinyblocks/tinyblocks.h>
/* ── Slots reutilizáveis ─────────────────────────────────────────────────── */
/* -- Slots reutilizáveis --- */
static const TinyBlocks_SlotDesc in_n[] = {{"n", TB_VALUE_INTEGER}};
static const TinyBlocks_SlotDesc in_ab[] = {{"a", TB_VALUE_INTEGER},
{"b", TB_VALUE_INTEGER}};
@@ -34,7 +34,7 @@ static const TinyBlocks_SlotDesc in_clamp[]= {{"val", TB_VALUE_INTEGER},
static const TinyBlocks_SlotDesc out_int[] = {{"out", TB_VALUE_INTEGER}};
static const TinyBlocks_SlotDesc out_txt[] = {{"out", TB_VALUE_TEXT}};
/* ── Implementações ──────────────────────────────────────────────────────── */
/* -- Implementações --- */
static void eval_square(TinyBlocks_Block* self, TinyBlocks* rt) {
TinyBlocks_Value v = tb_block_get_input(self, rt, 0);
int64_t n = v.kind==TB_VALUE_INTEGER ? v.as.integer : 0;
@@ -94,7 +94,7 @@ static void eval_int_to_text(TinyBlocks_Block* self, TinyBlocks* rt) {
tb_block_set_output(self, 0, tb_value_text(buf));
}
/* ── Registro da library ─────────────────────────────────────────────────── */
/* -- Registro da library --- */
static bool mylib_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
TinyBlocks_TypeBlock* t;
+9 -9
View File
@@ -1,15 +1,15 @@
/*
* python.c — Plugin TinyBlocks com blocos Python.*.
* python.c - Plugin TinyBlocks com blocos Python.*.
*
* Blocos:
* Python.Eval — avalia expressão Python com variáveis x0..x3
* Python.Run — executa script Python com variáveis x0..x3, captura stdout
* Python.Eval - avalia expressão Python com variáveis x0..x3
* Python.Run - executa script Python com variáveis x0..x3, captura stdout
*
* Compilar:
* make python-lib
*
* Carregar no editor:
* ./build/editor build/python.so ou Ctrl+O → build/python.so
* ./build/editor build/python.so ou Ctrl+O -> build/python.so
*
* Exemplos de expressões:
* x0 ** 2 + x1 ** 2
@@ -23,7 +23,7 @@
#include <tinyblocks/tinyblocks.h>
#include <tinyblocks-python/tb_python.h>
/* ── Helper: lê float de slot numérico ──────────────────────────────────── */
/* -- Helper: lê float de slot numérico --- */
static double gd(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t idx) {
TinyBlocks_Value v = tb_block_get_input(self, rt, idx);
if (v.kind == TB_VALUE_REAL) return v.as.real;
@@ -36,7 +36,7 @@ static const char* gs(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t idx) {
return (v.kind == TB_VALUE_TEXT && v.as.text) ? v.as.text : "";
}
/* ── Python.Eval ─────────────────────────────────────────────────────────── */
/* -- Python.Eval --- */
/*
* Inputs: expr (text), x0..x3 (real)
* Output: result (text)
@@ -52,7 +52,7 @@ static void eval_python_eval(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false;
}
/* ── Python.Run ──────────────────────────────────────────────────────────── */
/* -- Python.Run --- */
/*
* Inputs: code (text), x0..x3 (real)
* Output: stdout (text)
@@ -68,7 +68,7 @@ static void eval_python_run(TinyBlocks_Block* self, TinyBlocks* rt) {
self->dirty = false;
}
/* ── Slots ───────────────────────────────────────────────────────────────── */
/* -- Slots --- */
static const TinyBlocks_SlotDesc eval_in[] = {
{"expr", TB_VALUE_TEXT},
{"x0", TB_VALUE_REAL}, {"x1", TB_VALUE_REAL},
@@ -82,7 +82,7 @@ static const TinyBlocks_SlotDesc run_in[] = {
static const TinyBlocks_SlotDesc text_out[] = {{"result", TB_VALUE_TEXT}};
static const TinyBlocks_SlotDesc stdout_out[]= {{"stdout", TB_VALUE_TEXT}};
/* ── Registro ────────────────────────────────────────────────────────────── */
/* -- Registro --- */
static bool py_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
if (!tb_python_init()) return false;
+12 -12
View File
@@ -1,5 +1,5 @@
/*
* TinyBlocks — exemplo SDL2
* TinyBlocks - exemplo SDL2
*
* Demonstra o uso da library tinyblocks-sdl2 registrada estaticamente.
* Abre uma janela 640x480, desenha um retângulo pulsante e fecha ao pressionar
@@ -11,11 +11,11 @@
int main(void)
{
/* ── Runtime ──────────────────────────────────────────────────────────── */
/* -- Runtime --- */
TinyBlocks* rt = NULL;
if (!tinyblocks_init(&rt, NULL)) { fprintf(stderr, "init falhou\n"); return 1; }
/* ── Registra a library SDL2 estaticamente ────────────────────────────── */
/* -- Registra a library SDL2 estaticamente --- */
TinyBlocks_LibraryBlock* sdl2 = tb_library_register(rt, tb_sdl2_get_library());
if (!sdl2) {
fprintf(stderr, "Falha ao registrar SDL2: %s\n", tinyblocks_last_error(rt));
@@ -25,7 +25,7 @@ int main(void)
printf("Library '%s' carregada com %u blocos\n",
sdl2->base.name, sdl2->block_count);
/* ── Busca os TypeBlocks que vamos usar ───────────────────────────────── */
/* -- Busca os TypeBlocks que vamos usar --- */
TinyBlocks_TypeBlock* T_Init = (TinyBlocks_TypeBlock*)tb_library_find(sdl2, "SDL2.Init");
TinyBlocks_TypeBlock* T_Quit = (TinyBlocks_TypeBlock*)tb_library_find(sdl2, "SDL2.Quit");
TinyBlocks_TypeBlock* T_Window = (TinyBlocks_TypeBlock*)tb_library_find(sdl2, "SDL2.Window");
@@ -39,11 +39,11 @@ int main(void)
TinyBlocks_TypeBlock* T_DestroyRend = (TinyBlocks_TypeBlock*)tb_library_find(sdl2, "SDL2.DestroyRenderer");
TinyBlocks_TypeBlock* T_Delay = (TinyBlocks_TypeBlock*)tb_library_find(sdl2, "SDL2.Delay");
/* ── SDL2.Init ────────────────────────────────────────────────────────── */
/* -- SDL2.Init --- */
TinyBlocks_Block* b_init = tb_block_create(rt, T_Init);
tb_block_eval(b_init, rt);
/* ── SDL2.Window ─────────────────────────────────────────────────────── */
/* -- SDL2.Window --- */
TinyBlocks_TextBlock* lit_title = tb_text_block_create(rt, "TinyBlocks SDL2");
TinyBlocks_IntegerBlock* lit_cx = tb_integer_block_create(rt, -1); /* centered */
TinyBlocks_IntegerBlock* lit_cy = tb_integer_block_create(rt, -1);
@@ -58,12 +58,12 @@ int main(void)
tb_block_connect(b_window, 4, &lit_h->base, 0);
tb_block_eval(b_window, rt);
/* ── SDL2.Renderer ───────────────────────────────────────────────────── */
/* -- SDL2.Renderer --- */
TinyBlocks_Block* b_renderer = tb_block_create(rt, T_Renderer);
tb_block_connect(b_renderer, 0, b_window, 0);
tb_block_eval(b_renderer, rt);
/* ── Blocos reutilizáveis por frame ──────────────────────────────────── */
/* -- Blocos reutilizáveis por frame --- */
TinyBlocks_Block* b_poll = tb_block_create(rt, T_PollEvent);
TinyBlocks_Block* b_bg_color = tb_block_create(rt, T_SetColor);
TinyBlocks_Block* b_clear = tb_block_create(rt, T_Clear);
@@ -93,7 +93,7 @@ int main(void)
tb_block_connect(b_rect_color, 3, &lit_b2->base, 0);
tb_block_connect(b_rect_color, 4, &lit_255->base, 0);
/* Retângulo dinâmico — usaremos IntegerBlocks mutáveis para posição */
/* Retângulo dinâmico - usaremos IntegerBlocks mutáveis para posição */
TinyBlocks_IntegerBlock* lit_rx = tb_integer_block_create(rt, 100);
TinyBlocks_IntegerBlock* lit_ry = tb_integer_block_create(rt, 100);
TinyBlocks_IntegerBlock* lit_rw = tb_integer_block_create(rt, 200);
@@ -109,7 +109,7 @@ int main(void)
TinyBlocks_IntegerBlock* lit_delay = tb_integer_block_create(rt, 16); /* ~60fps */
tb_block_connect(b_delay, 0, &lit_delay->base, 0);
/* ── Loop principal ──────────────────────────────────────────────────── */
/* -- Loop principal --- */
printf("Janela aberta. Pressione Escape ou feche a janela para sair.\n");
int running = 1;
@@ -135,7 +135,7 @@ int main(void)
: 1.0 - (frame % 60) / 60.0)));
tb_integer_block_set(lit_rx, 80 + offset);
/* Renderização — cada bloco é avaliado na ordem correta */
/* Renderização - cada bloco é avaliado na ordem correta */
b_bg_color->dirty = true; tb_block_eval(b_bg_color, rt);
b_clear->dirty = true; tb_block_eval(b_clear, rt);
b_rect_color->dirty = true; tb_block_eval(b_rect_color, rt);
@@ -144,7 +144,7 @@ int main(void)
b_delay->dirty = true; tb_block_eval(b_delay, rt);
}
/* ── Limpeza SDL2 via blocos ──────────────────────────────────────────── */
/* -- Limpeza SDL2 via blocos --- */
TinyBlocks_Block* b_drend = tb_block_create(rt, T_DestroyRend);
TinyBlocks_Block* b_dwin = tb_block_create(rt, T_DestroyWin);
TinyBlocks_Block* b_quit = tb_block_create(rt, T_Quit);
+20 -20
View File
@@ -1,16 +1,16 @@
/*
* vector.c — Library de vetor 2D para o TinyBlocks Editor.
* vector.c - Library de vetor 2D para o TinyBlocks Editor.
*
* Blocos incluídos:
* Vector.BeginPath — inicia um novo path (sem inputs)
* Vector.MoveTo — move caneta para (x, y)
* Vector.LineTo — linha até (x, y)
* Vector.ClosePath — fecha sub-path atual
* Vector.Stroke — aplica traçado com cor/espessura RGBA
* Vector.Fill — aplica preenchimento RGBA ao path
* Vector.Rect — retângulo preenchido (usa Fill por cima)
* Vector.Circle — círculo preenchido
* Vector.Render — recebe vector e desenha no corpo do bloco (on_draw)
* Vector.BeginPath - inicia um novo path (sem inputs)
* Vector.MoveTo - move caneta para (x, y)
* Vector.LineTo - linha até (x, y)
* Vector.ClosePath - fecha sub-path atual
* Vector.Stroke - aplica traçado com cor/espessura RGBA
* Vector.Fill - aplica preenchimento RGBA ao path
* Vector.Rect - retângulo preenchido (usa Fill por cima)
* Vector.Circle - círculo preenchido
* Vector.Render - recebe vector e desenha no corpo do bloco (on_draw)
*
* Todos os blocos encadeiam: cada um recebe o vetor do anterior e devolve
* um novo com o comando acrescentado. Combine-os com Vector.Render no final.
@@ -19,7 +19,7 @@
* make vector
*
* Para carregar no editor:
* Ctrl+O → build/vector.so ou arraste build/vector.so para a janela
* Ctrl+O -> build/vector.so ou arraste build/vector.so para a janela
*/
#define _POSIX_C_SOURCE 200809L
@@ -29,7 +29,7 @@
#include <tinyblocks/tinyblocks.h>
#include <tinyblocks/tb_renderable_block.h>
/* ── Helper: lê float de qualquer slot numérico ──────────────────────────── */
/* -- Helper: lê float de qualquer slot numérico --- */
static float gf(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t idx) {
TinyBlocks_Value v = tb_block_get_input(self, rt, idx);
if (v.kind == TB_VALUE_REAL) return (float)v.as.real;
@@ -51,9 +51,9 @@ static TinyBlocks_VectorData* clone_vec(TinyBlocks_Block* self, TinyBlocks* rt)
(self)->dirty = false; \
} while(0)
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Implementações dos blocos
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static void eval_begin_path(TinyBlocks_Block* self, TinyBlocks* rt) {
(void)rt;
@@ -115,7 +115,7 @@ static void eval_circle(TinyBlocks_Block* self, TinyBlocks* rt) {
EMIT_VEC(self, v);
}
/* Vector.Render — passa o vetor adiante e tem on_render para preview */
/* Vector.Render - passa o vetor adiante e tem on_render para preview */
static void eval_render(TinyBlocks_Block* self, TinyBlocks* rt) {
TinyBlocks_Value v = tb_block_get_input(self, rt, 0);
/* Clona para manter o vector vivo no output (get_input é não-owning) */
@@ -138,9 +138,9 @@ static bool on_draw_vector(TinyBlocks_Block* self, TinyBlocks* rt,
return true;
}
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Descritores de slots
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static const TinyBlocks_SlotDesc out_vec[] = {{"vec", TB_VALUE_VECTOR}};
static const TinyBlocks_SlotDesc in_vec[] = {{"vec", TB_VALUE_VECTOR}};
static const TinyBlocks_SlotDesc in_vec_xy[] = {{"vec", TB_VALUE_VECTOR},
@@ -167,9 +167,9 @@ static const TinyBlocks_SlotDesc in_vec_cyr[] = {{"vec", TB_VALUE_VECTOR},
{"cy", TB_VALUE_REAL},
{"r", TB_VALUE_REAL}};
/* ══════════════════════════════════════════════════════════════════════════
/* ===
* Registro da library
* ══════════════════════════════════════════════════════════════════════════ */
* === */
static bool vector_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
TinyBlocks_TypeBlock* t;
@@ -188,7 +188,7 @@ static bool vector_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
#undef REG
/* Vector.Render tem on_draw — preview gráfico no corpo do bloco */
/* Vector.Render tem on_draw - preview gráfico no corpo do bloco */
t = tb_type_block_create(rt, "Vector.Render",
in_vec, 1, out_vec, 1, eval_render);
if (t) {