Entradas convertidas no core: fim dos helpers de conversão repetidos
- tb_block_input_text / _number / _integer / _truthy: a entrada do bloco
já convertida, despachando pela classe do valor. O texto de um valor
que não é texto fica em cache na conexão (sem buffers nos blocos).
- Saída com nome terminado em '?' vira o traço TB_SLOT_BOOLEAN na criação
do tipo (a convenção mora num lugar só; o editor só lê traços).
- Removidas ~35 funções locais (in_text, in_real, in_int, num, as_num,
input_name, value_num, value_truthy, value_to_str, item_text) em 22
libraries e no editor. Inteiros que truncavam (coordenadas de pixel)
continuam truncando; um número ligado a um campo de texto agora vira
texto ("42") em vez de "".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a5e36b3eed
commit
5ffc1741c2
27 files changed
+217
-416
No files matched your search
+31
-1
@@ -1,3 +1,4 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "tinyblocks/tinyblocks.h"
|
||||
@@ -127,8 +128,10 @@ void tb_block_destroy(TinyBlocks_Block* block, TinyBlocks* rt)
|
||||
tb_free(rt, block->name);
|
||||
|
||||
/* Libera valores de default dos inputs */
|
||||
for (uint32_t i = 0; i < block->input_count; ++i)
|
||||
for (uint32_t i = 0; i < block->input_count; ++i) {
|
||||
tb_value_free(&block->inputs[i].default_value);
|
||||
free(block->inputs[i].text_cache);
|
||||
}
|
||||
tb_free(rt, block->inputs);
|
||||
|
||||
for (uint32_t i = 0; i < block->output_count; ++i)
|
||||
@@ -230,6 +233,33 @@ TinyBlocks_Value tb_block_get_input(TinyBlocks_Block* self, TinyBlocks* rt,
|
||||
return conn->default_value;
|
||||
}
|
||||
|
||||
/* -- Entradas convertidas (polimorficas pela classe do valor) --- */
|
||||
const char* tb_block_input_text(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i)
|
||||
{
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, i);
|
||||
if (v.kind == TB_VALUE_TEXT) return v.as.text ? v.as.text : "";
|
||||
if (!self || i >= self->input_count) return "";
|
||||
TinyBlocks_Connection* c = &self->inputs[i];
|
||||
free(c->text_cache);
|
||||
c->text_cache = tb_value_to_string(v);
|
||||
return c->text_cache ? c->text_cache : "";
|
||||
}
|
||||
|
||||
double tb_block_input_number(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i, double def)
|
||||
{
|
||||
return tb_value_as_number(tb_block_get_input(self, rt, i), def);
|
||||
}
|
||||
|
||||
int64_t tb_block_input_integer(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i, int64_t def)
|
||||
{
|
||||
return tb_value_as_integer(tb_block_get_input(self, rt, i), def);
|
||||
}
|
||||
|
||||
bool tb_block_input_truthy(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i)
|
||||
{
|
||||
return tb_value_truthy(tb_block_get_input(self, rt, i));
|
||||
}
|
||||
|
||||
/* Toma ownership de v - o caller NÃO deve liberar v depois desta chamada.
|
||||
Se precisar manter v, passe tb_value_clone(v) em vez de v. */
|
||||
void tb_block_set_output(TinyBlocks_Block* self, uint32_t output_idx,
|
||||
|
||||
Reference in new issue
Block a user