Added user input support and many fixes. (0.16.5)
This commit is contained in:
parent
2b82a01fb5
commit
37abd5d6d3
11 changed files with 216 additions and 15 deletions
13
src/parser.c
13
src/parser.c
|
|
@ -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; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue