io library file creation

This commit is contained in:
Add00
2023-08-02 22:19:09 -04:00
parent 9b469e6eb0
commit 36b4a494ae
6 changed files with 26 additions and 0 deletions

14
repl/lib_io.c Normal file
View File

@@ -0,0 +1,14 @@
#include "lib_io.h"
#include <stdio.h>
//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;
}

5
repl/lib_io.h Normal file
View File

@@ -0,0 +1,5 @@
#pragma once
#include "toy_interpreter.h"
int Toy_hookIO(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias);

View File

@@ -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) {

View File

@@ -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);

1
test/scripts/lib/io.toy Normal file
View File

@@ -0,0 +1 @@
print "Nothing is here";

View File

@@ -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}
};