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
@@ -62,13 +62,6 @@ TB_API void tb_number_format(double x, int places, char* out, size_t cap) {
|
||||
|
||||
/* -- Entradas/saidas ------------------------------------------------------ */
|
||||
|
||||
static double num(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, i);
|
||||
if (v.kind == TB_VALUE_INTEGER) return (double)v.as.integer;
|
||||
if (v.kind == TB_VALUE_REAL) return v.as.real;
|
||||
if (v.kind == TB_VALUE_TEXT && v.as.text) return strtod(v.as.text, NULL);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/* Inteiro quando o resultado for exato (e couber), senao real */
|
||||
static void out_num(TinyBlocks_Block* self, double x) {
|
||||
@@ -89,7 +82,7 @@ static double trig(double x) { return tb_number_round_to(x, 10); }
|
||||
|
||||
/* -- Blocos --------------------------------------------------------------- */
|
||||
|
||||
#define N(i) num(self, rt, (i))
|
||||
#define N(i) tb_block_input_number(self, rt, (i), 0)
|
||||
|
||||
static void eval_div(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
double b = N(1);
|
||||
@@ -175,13 +168,13 @@ static void eval_from(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
}
|
||||
|
||||
static int in_base(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
int b = (int)llround(num(self, rt, i));
|
||||
int b = (int)llround(tb_block_input_number(self, rt, i, 0));
|
||||
return b < 2 ? 2 : b > 36 ? 36 : b;
|
||||
}
|
||||
|
||||
/* "(255) na base (16)" -> "ff" */
|
||||
static void eval_to_base(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
long long x = llround(num(self, rt, 0));
|
||||
long long x = llround(tb_block_input_number(self, rt, 0, 0));
|
||||
int b = in_base(self, rt, 1);
|
||||
char buf[72], *p = buf + sizeof(buf) - 1;
|
||||
*p = 0;
|
||||
@@ -198,7 +191,7 @@ static void eval_from_base(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
char buf[72];
|
||||
const char* s = buf;
|
||||
if (v.kind == TB_VALUE_TEXT) s = v.as.text ? v.as.text : "";
|
||||
else snprintf(buf, sizeof(buf), "%lld", llround(num(self, rt, 0)));
|
||||
else snprintf(buf, sizeof(buf), "%lld", llround(tb_block_input_number(self, rt, 0, 0)));
|
||||
int b = in_base(self, rt, 1);
|
||||
while (isspace((unsigned char)*s)) s++;
|
||||
char* e;
|
||||
|
||||
Reference in new issue
Block a user