--- /dev/null
+[submodule "linenoise"]
+ path = linenoise
+ url = https://github.com/antirez/linenoise
-all: flow.so
+all: flow.so io.so
uwu_include_path=../uwulang/
### `nolambda:io`
- `nolambda:io:print`: Accepts an arbitrary value as $0 and prints it to stdout, followed by a newline. Returns $0.
-- `nolambda:io:scan`: Reads a line from stdin and returns it as a string, without the newline character at the end. This is interally using readline.
+- `nolambda:io:scan`: Reads a line from stdin and returns it as a string, without the newline character at the end. If $0 is given, it is used as a prompt (after converting to string).
### `nolambda:fs`
UwUVMValue uwu_linear(UwUVMArgs *args)
{
if (args->num < 1)
- error("error: nolambda:flow:linear requires at least one argument");
+ error("error: nolambda:flow:linear requires at least one argument\n");
size_t return_arg = args->num - 1;
UwUVMValue uwu_error(UwUVMArgs *args)
{
if (args->num != 1)
- error("error: nolambda:flow:error exactly one argument");
+ error("error: nolambda:flow:error requires exactly one argument\n");
char *err = uwustr_get(uwuvm_get_arg(args, 0));
fprintf(stderr, "%s\n", err);
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "linenoise/linenoise.h"
+#include "common/err.h"
+#include "api/vm.h"
+#include "api/str.h"
+
+UwUVMValue uwu_print(UwUVMArgs *args)
+{
+ if (args->num != 1)
+ error("error: nolambda:io:print requires exactly one argument\n");
+
+ UwUVMValue value = uwuvm_get_arg(args, 0);
+
+ char *str = uwustr_get(value);
+ printf("%s\n", str);
+ free(str);
+
+ return uwuvm_clone_value(value);
+}
+
+UwUVMValue uwu_scan(UwUVMArgs *args)
+{
+ char *prompt = NULL;
+
+ if (args->num == 0)
+ prompt = strdup("");
+ else if (args->num == 1)
+ prompt = uwustr_get(uwuvm_get_arg(args, 0));
+ else
+ error("error: nolambda:io:scan requires exactly one or zero arguments\n");
+
+ char *return_string = linenoise(prompt);
+ UwUVMValue return_value = uwustr_create(return_string);
+
+ linenoiseFree(return_string);
+ free(prompt);
+
+ return return_value;
+}
+
+#include "linenoise/linenoise.c"
--- /dev/null
+Subproject commit 97d2850af13c339369093b78abe5265845d78220
--- /dev/null
+main flow:linear(
+ io:print("please enter something:"),
+ io:print(io:scan),
+ io:print(:str:cat(
+ "your input: ",
+ io:scan("please enter something else: ")
+ )),
+ "success"
+)