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

2
Toy

Submodule Toy updated: c86c5800a7...f4469fc53d

View File

@@ -11,7 +11,7 @@ var y: int = 50;
var xspeed: int = 0;
var yspeed: int = 0;
//accessors
//accessors - variables are private, functions are public
fn getX(node: opaque) {
return x;
}
@@ -24,7 +24,7 @@ fn getY(node: opaque) {
fn onInit(node: opaque) {
print "render.toy:onInit() called";
node.loadTexture("assets/sprites/character.png");
node.loadTexture("sprites:/character.png");
parent = node.getNodeParent();
}

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] == '.') {

View File

@@ -10,6 +10,7 @@ int main(int argc, char* argv[]) {
//the drive system uses a LiteralDictionary, which must be initialized with this
Toy_initDriveDictionary();
{
//create a pair of literals, the first for the drive name, the second for the path
Toy_Literal driveLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("scripts"));
Toy_Literal pathLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("assets/scripts"));
@@ -20,6 +21,20 @@ int main(int argc, char* argv[]) {
//these literals are no longer needed
Toy_freeLiteral(driveLiteral);
Toy_freeLiteral(pathLiteral);
}
{
//create a pair of literals, the first for the drive name, the second for the path
Toy_Literal driveLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("sprites"));
Toy_Literal pathLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("assets/sprites"));
//set these within the drive dictionary
Toy_setLiteralDictionary(Toy_getDriveDictionary(), driveLiteral, pathLiteral);
//these literals are no longer needed
Toy_freeLiteral(driveLiteral);
Toy_freeLiteral(pathLiteral);
}
//run the rest of your program
Box_initEngine();