Tweaks while I sort stuff out

This commit is contained in:
2023-01-27 07:04:21 +00:00
parent 5251579e70
commit 3b5b399f4f
5 changed files with 52 additions and 27 deletions

View File

@@ -34,6 +34,12 @@ static int nativeLoadNode(Toy_Interpreter* interpreter, Toy_LiteralArray* argume
Toy_Literal filePathLiteral = Toy_getFilePathLiteral(interpreter, &drivePathLiteral);
if (!TOY_IS_STRING(filePathLiteral)) {
Toy_freeLiteral(drivePathLiteral);
Toy_freeLiteral(filePathLiteral);
return -1;
}
Toy_freeLiteral(drivePathLiteral); //not needed anymore
//load the new node
@@ -287,12 +293,12 @@ static int nativeLoadTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
}
//extract the arguments
Toy_Literal fname = Toy_popLiteralArray(arguments);
Toy_Literal drivePathLiteral = Toy_popLiteralArray(arguments);
Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments);
Toy_Literal fnameIdn = fname;
if (TOY_IS_IDENTIFIER(fname) && Toy_parseIdentifierToValue(interpreter, &fname)) {
Toy_freeLiteral(fnameIdn);
Toy_Literal drivePathLiteralIdn = drivePathLiteral;
if (TOY_IS_IDENTIFIER(drivePathLiteral) && Toy_parseIdentifierToValue(interpreter, &drivePathLiteral)) {
Toy_freeLiteral(drivePathLiteralIdn);
}
Toy_Literal nodeIdn = nodeLiteral;
@@ -301,13 +307,23 @@ static int nativeLoadTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
}
//check argument types
if (!TOY_IS_STRING(fname) || !TOY_IS_OPAQUE(nodeLiteral)) {
if (!TOY_IS_STRING(drivePathLiteral) || !TOY_IS_OPAQUE(nodeLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to loadTextureEngineNode\n");
Toy_freeLiteral(fname);
Toy_freeLiteral(drivePathLiteral);
Toy_freeLiteral(nodeLiteral);
return -1;
}
Toy_Literal filePathLiteral = Toy_getFilePathLiteral(interpreter, &drivePathLiteral);
if (!TOY_IS_STRING(filePathLiteral)) {
Toy_freeLiteral(drivePathLiteral);
Toy_freeLiteral(filePathLiteral);
return -1;
}
Toy_freeLiteral(drivePathLiteral); //not needed anymore
//actually load TODO: number the opaques, and check the numbers
Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral);
@@ -315,16 +331,17 @@ static int nativeLoadTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
Box_freeTextureEngineNode(node);
}
if (Box_loadTextureEngineNode(node, Toy_toCString(TOY_AS_STRING(fname))) != 0) {
if (Box_loadTextureEngineNode(node, Toy_toCString(TOY_AS_STRING(filePathLiteral))) != 0) {
interpreter->errorOutput("Failed to load the texture into the EngineNode\n");
Toy_freeLiteral(fname);
Toy_freeLiteral(filePathLiteral);
Toy_freeLiteral(nodeLiteral);
return -1;
}
//cleanup
Toy_freeLiteral(fname);
Toy_freeLiteral(filePathLiteral);
Toy_freeLiteral(nodeLiteral);
return 0;
}

View File

@@ -618,13 +618,6 @@ Toy_Literal Toy_getFilePathLiteral(Toy_Interpreter* interpreter, Toy_Literal* dr
Toy_deleteRefString(path);
Toy_deleteRefString(drivePath);
//check for file extensions
if (!(filePath[realLength - 5] == '.' && filePath[realLength - 4] == 't' && filePath[realLength - 3] == 'o' && filePath[realLength - 2] == 'y')) {
interpreter->errorOutput("Bad script file extension (expected .toy)\n"); //TODO: add a bytecode version too
TOY_FREE_ARRAY(char, filePath, realLength + 1);
return TOY_TO_NULL_LITERAL;
}
//check for break-out attempts
for (int i = 0; i < realLength - 1; i++) {
if (filePath[i] == '.' && filePath[i + 1] == '.') {