mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
io library file creation
This commit is contained in:
14
repl/lib_io.c
Normal file
14
repl/lib_io.c
Normal 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
5
repl/lib_io.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "toy_interpreter.h"
|
||||
|
||||
int Toy_hookIO(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias);
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
1
test/scripts/lib/io.toy
Normal file
@@ -0,0 +1 @@
|
||||
print "Nothing is here";
|
||||
@@ -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}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user