mirror of https://gitlab.com/nakst/essence
				
				
				
			scripting engine: add FileAppend; automated builds: make sure automated_build is set after getting the toolchain
This commit is contained in:
		
							parent
							
								
									843cf72c20
								
							
						
					
					
						commit
						0d59a6dafd
					
				| 
						 | 
					@ -280,6 +280,19 @@ int ExternalFileWriteAll(ExecutionContext *context, Value *returnValue) {
 | 
				
			||||||
	return 2;
 | 
						return 2;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ExternalFileAppend(ExecutionContext *context, Value *returnValue) {
 | 
				
			||||||
 | 
						STACK_POP_STRING_2(entryText, entryBytes, entry2Text, entry2Bytes);
 | 
				
			||||||
 | 
						returnValue->i = 0;
 | 
				
			||||||
 | 
						EsFileInformation information = EsFileOpen(entryText, entryBytes, ES_FILE_WRITE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (information.error == ES_SUCCESS) {
 | 
				
			||||||
 | 
							returnValue->i = EsFileWriteSync(information.handle, information.size, entry2Bytes, entry2Text);
 | 
				
			||||||
 | 
							EsHandleClose(information.handle);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 2;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ExternalFileGetSize(ExecutionContext *context, Value *returnValue) {
 | 
					int ExternalFileGetSize(ExecutionContext *context, Value *returnValue) {
 | 
				
			||||||
	STACK_POP_STRING(entryText, entryBytes);
 | 
						STACK_POP_STRING(entryText, entryBytes);
 | 
				
			||||||
	EsDirectoryChild information;
 | 
						EsDirectoryChild information;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -509,6 +509,7 @@ char baseModuleSource[] = {
 | 
				
			||||||
	"bool PathSetDefaultPrefixToScriptSourceDirectory() #extcall;"
 | 
						"bool PathSetDefaultPrefixToScriptSourceDirectory() #extcall;"
 | 
				
			||||||
	"str FileReadAll(str path) #extcall;" // TODO Returning an error?
 | 
						"str FileReadAll(str path) #extcall;" // TODO Returning an error?
 | 
				
			||||||
	"bool FileWriteAll(str path, str x) #extcall;" // TODO Returning an error?
 | 
						"bool FileWriteAll(str path, str x) #extcall;" // TODO Returning an error?
 | 
				
			||||||
 | 
						"bool FileAppend(str path, str x) #extcall;" // TODO Returning an error?
 | 
				
			||||||
	"bool FileCopy(str source, str destination) #extcall;"
 | 
						"bool FileCopy(str source, str destination) #extcall;"
 | 
				
			||||||
	"int FileGetSize(str path) #extcall;" // Returns -1 on error. TODO Returning an error code.
 | 
						"int FileGetSize(str path) #extcall;" // Returns -1 on error. TODO Returning an error code.
 | 
				
			||||||
					      
 | 
										      
 | 
				
			||||||
| 
						 | 
					@ -704,6 +705,7 @@ int ExternalPathGetDefaultPrefix(ExecutionContext *context, Value *returnValue);
 | 
				
			||||||
int ExternalPathSetDefaultPrefixToScriptSourceDirectory(ExecutionContext *context, Value *returnValue);
 | 
					int ExternalPathSetDefaultPrefixToScriptSourceDirectory(ExecutionContext *context, Value *returnValue);
 | 
				
			||||||
int ExternalFileReadAll(ExecutionContext *context, Value *returnValue);
 | 
					int ExternalFileReadAll(ExecutionContext *context, Value *returnValue);
 | 
				
			||||||
int ExternalFileWriteAll(ExecutionContext *context, Value *returnValue);
 | 
					int ExternalFileWriteAll(ExecutionContext *context, Value *returnValue);
 | 
				
			||||||
 | 
					int ExternalFileAppend(ExecutionContext *context, Value *returnValue);
 | 
				
			||||||
int ExternalFileCopy(ExecutionContext *context, Value *returnValue);
 | 
					int ExternalFileCopy(ExecutionContext *context, Value *returnValue);
 | 
				
			||||||
int ExternalFileGetSize(ExecutionContext *context, Value *returnValue);
 | 
					int ExternalFileGetSize(ExecutionContext *context, Value *returnValue);
 | 
				
			||||||
int ExternalPersistRead(ExecutionContext *context, Value *returnValue);
 | 
					int ExternalPersistRead(ExecutionContext *context, Value *returnValue);
 | 
				
			||||||
| 
						 | 
					@ -742,6 +744,7 @@ ExternalFunction externalFunctions[] = {
 | 
				
			||||||
	{ .cName = "PathSetDefaultPrefixToScriptSourceDirectory", .callback = ExternalPathSetDefaultPrefixToScriptSourceDirectory },
 | 
						{ .cName = "PathSetDefaultPrefixToScriptSourceDirectory", .callback = ExternalPathSetDefaultPrefixToScriptSourceDirectory },
 | 
				
			||||||
	{ .cName = "FileReadAll", .callback = ExternalFileReadAll },
 | 
						{ .cName = "FileReadAll", .callback = ExternalFileReadAll },
 | 
				
			||||||
	{ .cName = "FileWriteAll", .callback = ExternalFileWriteAll },
 | 
						{ .cName = "FileWriteAll", .callback = ExternalFileWriteAll },
 | 
				
			||||||
 | 
						{ .cName = "FileAppend", .callback = ExternalFileAppend },
 | 
				
			||||||
	{ .cName = "FileCopy", .callback = ExternalFileCopy },
 | 
						{ .cName = "FileCopy", .callback = ExternalFileCopy },
 | 
				
			||||||
	{ .cName = "FileGetSize", .callback = ExternalFileGetSize },
 | 
						{ .cName = "FileGetSize", .callback = ExternalFileGetSize },
 | 
				
			||||||
	{ .cName = "PersistRead", .callback = ExternalPersistRead },
 | 
						{ .cName = "PersistRead", .callback = ExternalPersistRead },
 | 
				
			||||||
| 
						 | 
					@ -5507,6 +5510,23 @@ int ExternalFileWriteAll(ExecutionContext *context, Value *returnValue) {
 | 
				
			||||||
	return 2;
 | 
						return 2;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ExternalFileAppend(ExecutionContext *context, Value *returnValue) {
 | 
				
			||||||
 | 
						STACK_POP_STRING_2(entryText, entryBytes, entry2Text, entry2Bytes);
 | 
				
			||||||
 | 
						returnValue->i = 0;
 | 
				
			||||||
 | 
						if (entryBytes == 0) return 2;
 | 
				
			||||||
 | 
						char *temporary = StringZeroTerminate(entryText, entryBytes);
 | 
				
			||||||
 | 
						if (!temporary) return 3;
 | 
				
			||||||
 | 
						FILE *f = fopen(temporary, "ab");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (f) {
 | 
				
			||||||
 | 
							returnValue->i = entry2Bytes == fwrite(entry2Text, 1, entry2Bytes, f);
 | 
				
			||||||
 | 
							if (fclose(f)) returnValue->i = 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						free(temporary);
 | 
				
			||||||
 | 
						return 2;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ExternalPathGetDefaultPrefix(ExecutionContext *context, Value *returnValue) {
 | 
					int ExternalPathGetDefaultPrefix(ExecutionContext *context, Value *returnValue) {
 | 
				
			||||||
	(void) returnValue;
 | 
						(void) returnValue;
 | 
				
			||||||
	char *data = (char *) malloc(10000);
 | 
						char *data = (char *) malloc(10000);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,6 +46,7 @@ void Setup(bool forAutomation) {
 | 
				
			||||||
	if forAutomation {
 | 
						if forAutomation {
 | 
				
			||||||
		assert FileWriteAll("bin/build_config.ini", "accepted_license=1\nautomated_build=1\n");
 | 
							assert FileWriteAll("bin/build_config.ini", "accepted_license=1\nautomated_build=1\n");
 | 
				
			||||||
		assert SystemShellExecute("bin/build get-toolchain");
 | 
							assert SystemShellExecute("bin/build get-toolchain");
 | 
				
			||||||
 | 
							assert FileAppend("bin/build_config.ini", "\nautomated_build=1\n");
 | 
				
			||||||
		assert FileWriteAll("bin/commit.txt", StringSlice(StringSplitByCharacter(SystemShellEvaluate("git log"), "\n", true)[0], 8, 15));
 | 
							assert FileWriteAll("bin/commit.txt", StringSlice(StringSplitByCharacter(SystemShellEvaluate("git log"), "\n", true)[0], 8, 15));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue