diff --git a/repl/lib_io.c b/repl/lib_io.c new file mode 100644 index 0000000..70b1944 --- /dev/null +++ b/repl/lib_io.c @@ -0,0 +1,14 @@ +#include "lib_io.h" + +#include + +//call the hook +typedef struct Natives { + char* name; + Toy_NativeFn fn; +} Natives; + + +int Toy_hookIO(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias) { + return 1; +} \ No newline at end of file diff --git a/repl/lib_io.h b/repl/lib_io.h new file mode 100644 index 0000000..ec7264c --- /dev/null +++ b/repl/lib_io.h @@ -0,0 +1,5 @@ +#pragma once + +#include "toy_interpreter.h" + +int Toy_hookIO(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias); diff --git a/repl/repl_main.c b/repl/repl_main.c index bee774f..cf91d5b 100644 --- a/repl/repl_main.c +++ b/repl/repl_main.c @@ -5,6 +5,7 @@ #include "lib_random.h" #include "lib_runner.h" #include "lib_math.h" +#include "lib_io.h" #include "toy_console_colors.h" @@ -32,6 +33,7 @@ void repl(const char* initialInput) { Toy_injectNativeHook(&interpreter, "random", Toy_hookRandom); Toy_injectNativeHook(&interpreter, "runner", Toy_hookRunner); Toy_injectNativeHook(&interpreter, "math", Toy_hookMath); + Toy_injectNativeHook(&interpreter, "io", Toy_hookIO); for(;;) { if (!initialInput) { diff --git a/repl/repl_tools.c b/repl/repl_tools.c index 0310d1e..07d31ff 100644 --- a/repl/repl_tools.c +++ b/repl/repl_tools.c @@ -4,6 +4,7 @@ #include "lib_random.h" #include "lib_runner.h" #include "lib_math.h" +#include "lib_io.h" #include "toy_console_colors.h" @@ -117,6 +118,7 @@ void Toy_runBinary(const unsigned char* tb, size_t size) { Toy_injectNativeHook(&interpreter, "random", Toy_hookRandom); Toy_injectNativeHook(&interpreter, "runner", Toy_hookRunner); Toy_injectNativeHook(&interpreter, "math", Toy_hookMath); + Toy_injectNativeHook(&interpreter, "io", Toy_hookIO); Toy_runInterpreter(&interpreter, tb, (int)size); Toy_freeInterpreter(&interpreter); diff --git a/test/scripts/lib/io.toy b/test/scripts/lib/io.toy new file mode 100644 index 0000000..b55d06e --- /dev/null +++ b/test/scripts/lib/io.toy @@ -0,0 +1 @@ +print "Nothing is here"; \ No newline at end of file diff --git a/test/test_libraries.c b/test/test_libraries.c index 998c272..c33e167 100644 --- a/test/test_libraries.c +++ b/test/test_libraries.c @@ -19,6 +19,7 @@ #include "../repl/lib_random.h" #include "../repl/lib_runner.h" #include "../repl/lib_math.h" +#include "../repl/lib_io.h" //supress the print output static void noPrintFn(const char* output) { @@ -78,6 +79,7 @@ int main() { {"runner.toy", "runner", Toy_hookRunner}, {"random.toy", "random", Toy_hookRandom}, {"math.toy", "math", Toy_hookMath}, + {"io.toy", "io", Toy_hookIO}, {NULL, NULL, NULL} };