1
0
Fork 0
forked from fun/fun

Added user input support and many fixes. (0.16.5)

This commit is contained in:
Johannes Findeisen 2025-10-02 00:53:51 +02:00
commit 37abd5d6d3
11 changed files with 216 additions and 15 deletions

View file

@ -641,6 +641,19 @@ static int emit_primary(Bytecode *bc, const char *src, size_t len, size_t *pos)
free(name);
return 1;
}
if (strcmp(name, "input") == 0) {
(*pos)++; /* '(' */
int hasPrompt = 0;
skip_spaces(src, len, pos);
if (*pos < len && src[*pos] != ')') {
if (!emit_expression(bc, src, len, pos)) { parser_fail(*pos, "input expects 0 or 1 argument"); free(name); return 0; }
hasPrompt = 1;
}
if (!consume_char(src, len, pos, ')')) { parser_fail(*pos, "Expected ')' after input arg(s)"); free(name); return 0; }
bytecode_add_instruction(bc, OP_INPUT_LINE, hasPrompt ? 1 : 0);
free(name);
return 1;
}
if (strcmp(name, "env") == 0) {
(*pos)++; /* '(' */
if (!emit_expression(bc, src, len, pos)) { parser_fail(*pos, "env expects 1 argument"); free(name); return 0; }