🐐 Several fixes

This commit is contained in:
2026-04-16 17:48:45 +02:00
parent 0b13d9f027
commit c720d75c79
3 changed files with 220 additions and 65 deletions

View File

@@ -221,11 +221,11 @@ static int write_val(CentValue v, char *buf, int bufsz) {
case CENT_BOOL:
if (v.bval) {
if (buf && bufsz > 5) { memcpy(buf, "VERVS", 5); buf[5] = '\0'; }
return 5;
if (buf && bufsz > 7) { memcpy(buf, "VERITAS", 7); buf[7] = '\0'; }
return 7;
} else {
if (buf && bufsz > 6) { memcpy(buf, "FALSVS", 6); buf[6] = '\0'; }
return 6;
if (buf && bufsz > 8) { memcpy(buf, "FALSITAS", 8); buf[8] = '\0'; }
return 8;
}
case CENT_NULL:
@@ -527,9 +527,13 @@ void cent_list_push(CentValue *lst, CentValue v) {
CentValue cent_list_index(CentValue lst, CentValue idx) {
if (lst.type != CENT_LIST)
cent_type_error("index requires a list");
if (idx.type != CENT_INT)
long i;
if (idx.type == CENT_INT)
i = idx.ival;
else if (idx.type == CENT_FRAC && idx.fval.den == 1)
i = idx.fval.num;
else
cent_type_error("list index must be an integer");
long i = idx.ival;
if (i < 1 || i > lst.lval.len)
cent_runtime_error("list index out of range");
return lst.lval.items[i - 1];