From 0ced372a772a1eea5e27b1b16a10011ccb5a90b8 Mon Sep 17 00:00:00 2001 From: Matthieu Bessat Date: Mon, 16 May 2022 11:02:04 +0200 Subject: [PATCH] feat: add guessing example --- README.md | 4 +++- examples/guessing.ltor | 23 +++++++++++++++++++++++ src/funcs.c | 6 +++++- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 examples/guessing.ltor diff --git a/README.md b/README.md index 33c9119..da6bb20 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,8 @@ ToDo List: - [ ] add inclusive operators like '!=', '>=', '<=' - [ ] add support for priority operators - [X] add input_number() std function -- [ ] add type() std function +- [ ] add null type (dirty way to handle no returns and some errors) +- [ ] add type() std function and others type checking functions - [X] add ceil() and floor() std functions - [X] base of the CLI - [ ] evaluate expression from stdin @@ -149,6 +150,7 @@ floor(nb) random_int(min, max) random_float(min, max) type(var) -> return the type of a var as int +is_null(var) is_int(var) is_float(var) print_string(str) diff --git a/examples/guessing.ltor b/examples/guessing.ltor new file mode 100644 index 0000000..baaff52 --- /dev/null +++ b/examples/guessing.ltor @@ -0,0 +1,23 @@ +set i to 0 +set toGuess to random_int(0, 100) +while 1 do + set guessed to input_number() + if i > 20 then + # do you really want to continue? + break + end + if guessed = toGuess then + # success + print_ascii(83) + break + end + if guessed < toGuess then + # too low + print_ascii(76) + end + if guessed > toGuess then + # too high + print_ascii(72) + end + set i to i+1 +end diff --git a/src/funcs.c b/src/funcs.c index af89baf..92696d6 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -134,7 +134,11 @@ int input_number_impl(int* res, unsigned char* resType, unsigned char* types, in return 0; } } - return 1; + // we didn't manage to parse the number + *resType = TYPE_INT; + *res = 0; + + return 0; } int simple_float_func(float (*func)(float), int* res, unsigned char* resType, unsigned char* types, int* args)