Wrote docs for arrays and dicts, I think I'm done

This commit is contained in:
2023-02-19 03:43:46 +11:00
committed by GitHub
parent 047435a7f5
commit 2c594f726d
4 changed files with 123 additions and 3 deletions

44
c-api/repl_tools_h.md Normal file
View File

@@ -0,0 +1,44 @@
# repl_tools.h
This header provides a number of tools for compiling and running Toy, and is used primarily by the repl. However, it can also be modified and used by any host program with little effort.
This is not a core part of the Toy library, and as such `repl_tools.h` and `repl_tools.c` can both be found in the `repl/` folder.
### const char* Toy_readFile(const char* path, size_t* fileSize)
This function reads in a file, and returns it as a constant buffer. It also sets the variable pointed to by `fileSize` to the size of the given buffer.
On error, this function returns `NULL`.
### int Toy_writeFile(const char* path, const unsigned char* bytes, size_t size)
This function writes the buffer pointed to by `bytes` to a file specified by `path`. The buffer's size should be specified by `size`.
On error, this function returns a non-zero value.
### const unsigned char* Toy_compileString(const char* source, size_t* size)
This function takes a cstring of Toy source code, and returns a compiled buffer based on that source code. The variable pointed to by `size` is set to the size of the bytecode.
On error, this function returns `NULL`.
### void Toy_runBinary(const unsigned char* tb, size_t size)
This function takes a bytecode array of `size` size, and executes it. The libraries available to the code are:
* lib_about
* lib_standard
* lib_runner
### void Toy_runBinaryFile(const char* fname)
This function loads in the binary file specified by `fname`, and passes it to `Toy_runBinary`.
### void Toy_runSource(const char* source)
This function compiles the source with `Toy_compileString`, and passes it to `Toy_runBinary`.
### void Toy_runSourceFile(const char* fname)
This function loads in the file specified by `fname`, compiles it, and passes it to `Toy_runBinary`.