🐐 Several fixes
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user