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
@@ -211,56 +211,46 @@ void tb_regex_free_list(char** list) {
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- Blocos */
|
||||
static const char* in_text(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, i);
|
||||
return (v.kind == TB_VALUE_TEXT && v.as.text) ? v.as.text : "";
|
||||
}
|
||||
static double in_real(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, i);
|
||||
if (v.kind == TB_VALUE_REAL) return v.as.real;
|
||||
if (v.kind == TB_VALUE_INTEGER) return (double)v.as.integer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void eval_test(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
bool ok = tb_regex_test(in_text(self, rt, 0), in_text(self, rt, 1));
|
||||
bool ok = tb_regex_test(tb_block_input_text(self, rt, 0), tb_block_input_text(self, rt, 1));
|
||||
tb_block_set_output(self, 0, tb_value_integer(ok ? 1 : 0));
|
||||
self->dirty = false;
|
||||
}
|
||||
static void eval_match(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
bool ok = tb_regex_match(in_text(self, rt, 0), in_text(self, rt, 1));
|
||||
bool ok = tb_regex_match(tb_block_input_text(self, rt, 0), tb_block_input_text(self, rt, 1));
|
||||
tb_block_set_output(self, 0, tb_value_integer(ok ? 1 : 0));
|
||||
self->dirty = false;
|
||||
}
|
||||
static void eval_find(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
char* s = tb_regex_find(in_text(self, rt, 0), in_text(self, rt, 1));
|
||||
char* s = tb_regex_find(tb_block_input_text(self, rt, 0), tb_block_input_text(self, rt, 1));
|
||||
tb_block_set_output(self, 0, tb_value_text(s ? s : ""));
|
||||
free(s);
|
||||
self->dirty = false;
|
||||
}
|
||||
static void eval_group(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
char* s = tb_regex_group(in_text(self, rt, 0), in_text(self, rt, 1), (int)in_real(self, rt, 2));
|
||||
char* s = tb_regex_group(tb_block_input_text(self, rt, 0), tb_block_input_text(self, rt, 1), (int)tb_block_input_number(self, rt, 2, 0));
|
||||
tb_block_set_output(self, 0, tb_value_text(s ? s : ""));
|
||||
free(s);
|
||||
self->dirty = false;
|
||||
}
|
||||
static void eval_count(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
tb_block_set_output(self, 0, tb_value_integer(tb_regex_count(in_text(self, rt, 0), in_text(self, rt, 1))));
|
||||
tb_block_set_output(self, 0, tb_value_integer(tb_regex_count(tb_block_input_text(self, rt, 0), tb_block_input_text(self, rt, 1))));
|
||||
self->dirty = false;
|
||||
}
|
||||
static void eval_groups(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
tb_block_set_output(self, 0, tb_value_integer(tb_regex_group_count("", in_text(self, rt, 1))));
|
||||
tb_block_set_output(self, 0, tb_value_integer(tb_regex_group_count("", tb_block_input_text(self, rt, 1))));
|
||||
self->dirty = false;
|
||||
}
|
||||
static void eval_replace(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
char* s = tb_regex_replace(in_text(self, rt, 0), in_text(self, rt, 1), in_text(self, rt, 2));
|
||||
char* s = tb_regex_replace(tb_block_input_text(self, rt, 0), tb_block_input_text(self, rt, 1), tb_block_input_text(self, rt, 2));
|
||||
tb_block_set_output(self, 0, tb_value_text(s ? s : ""));
|
||||
free(s);
|
||||
self->dirty = false;
|
||||
}
|
||||
static void eval_split(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
int n = 0;
|
||||
char** parts = tb_regex_split(in_text(self, rt, 0), in_text(self, rt, 1), &n);
|
||||
char** parts = tb_regex_split(tb_block_input_text(self, rt, 0), tb_block_input_text(self, rt, 1), &n);
|
||||
TinyBlocks_JsonValue* arr = tb_json_array();
|
||||
if (arr) {
|
||||
for (int i = 0; parts && parts[i]; i++) {
|
||||
|
||||
Reference in new issue
Block a user