mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Hooks can't be dict keys, tweaked Toy_readFile
This commit is contained in:
@@ -49,7 +49,7 @@ static int nativeLoadScript(Toy_Interpreter* interpreter, Toy_LiteralArray* argu
|
||||
|
||||
//load and compile the bytecode
|
||||
size_t fileSize = 0;
|
||||
const char* source = Toy_readFile(filePath, &fileSize);
|
||||
const char* source = (const char*)Toy_readFile(filePath, &fileSize);
|
||||
|
||||
if (!source) {
|
||||
interpreter->errorOutput("Failed to load source file\n");
|
||||
|
||||
@@ -180,7 +180,7 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
//compile and save
|
||||
size_t size = 0;
|
||||
const char* source = Toy_readFile(Toy_commandLine.compilefile, &size);
|
||||
const char* source = (const char*)Toy_readFile(Toy_commandLine.compilefile, &size);
|
||||
if (!source) {
|
||||
return 1;
|
||||
}
|
||||
@@ -220,7 +220,7 @@ int main(int argc, const char* argv[]) {
|
||||
}
|
||||
|
||||
size_t size;
|
||||
initialSource = Toy_readFile(Toy_commandLine.initialfile, &size);
|
||||
initialSource = (const char*)Toy_readFile(Toy_commandLine.initialfile, &size);
|
||||
}
|
||||
|
||||
repl(initialSource);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
//IO functions
|
||||
const char* Toy_readFile(const char* path, size_t* fileSize) {
|
||||
const unsigned char* Toy_readFile(const char* path, size_t* fileSize) {
|
||||
FILE* file = fopen(path, "rb");
|
||||
|
||||
if (file == NULL) {
|
||||
@@ -26,14 +26,14 @@ const char* Toy_readFile(const char* path, size_t* fileSize) {
|
||||
*fileSize = ftell(file);
|
||||
rewind(file);
|
||||
|
||||
char* buffer = (char*)malloc(*fileSize + 1);
|
||||
unsigned char* buffer = (unsigned char*)malloc(*fileSize + 1);
|
||||
|
||||
if (buffer == NULL) {
|
||||
fprintf(stderr, TOY_CC_ERROR "Not enough memory to read \"%s\"\n" TOY_CC_RESET, path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t bytesRead = fread(buffer, sizeof(char), *fileSize, file);
|
||||
size_t bytesRead = fread(buffer, sizeof(unsigned char), *fileSize, file);
|
||||
|
||||
buffer[*fileSize] = '\0'; //NOTE: fread doesn't append this
|
||||
|
||||
@@ -120,7 +120,7 @@ void Toy_runBinary(const unsigned char* tb, size_t size) {
|
||||
|
||||
void Toy_runBinaryFile(const char* fname) {
|
||||
size_t size = 0; //not used
|
||||
const unsigned char* tb = (const unsigned char*)Toy_readFile(fname, &size);
|
||||
const unsigned char* tb = Toy_readFile(fname, &size);
|
||||
if (!tb) {
|
||||
return;
|
||||
}
|
||||
@@ -140,7 +140,7 @@ void Toy_runSource(const char* source) {
|
||||
|
||||
void Toy_runSourceFile(const char* fname) {
|
||||
size_t size = 0; //not used
|
||||
const char* source = Toy_readFile(fname, &size);
|
||||
const char* source = (const char*)Toy_readFile(fname, &size);
|
||||
if (!source) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "toy_common.h"
|
||||
|
||||
const char* Toy_readFile(const char* path, size_t* fileSize);
|
||||
const unsigned char* Toy_readFile(const char* path, size_t* fileSize);
|
||||
int Toy_writeFile(const char* path, const unsigned char* bytes, size_t size);
|
||||
|
||||
const unsigned char* Toy_compileString(const char* source, size_t* size);
|
||||
|
||||
Reference in New Issue
Block a user