58 lines
1.3 KiB
C
58 lines
1.3 KiB
C
/**
|
|
* Copyright (c) 2025 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "asset/asset.h"
|
|
#include "assert/assert.h"
|
|
|
|
errorret_t assetScriptHandler(assetcustom_t custom) {
|
|
assertNotNull(custom.zipFile, "Custom asset zip file cannot be NULL");
|
|
assertNotNull(custom.output, "Custom asset output cannot be NULL");
|
|
|
|
assetscript_t *script = (assetscript_t *)custom.output;
|
|
errorChain(assetScriptInit(script, custom.zipFile));
|
|
|
|
errorOk();
|
|
}
|
|
|
|
errorret_t assetScriptInit(
|
|
assetscript_t *script,
|
|
zip_file_t *zipFile
|
|
) {
|
|
assertNotNull(script, "Script asset cannot be NULL");
|
|
assertNotNull(zipFile, "Zip file cannot be NULL");
|
|
|
|
// We now own the zip file handle.
|
|
script->zip = zipFile;
|
|
|
|
errorOk();
|
|
}
|
|
|
|
const char_t * assetScriptReader(lua_State* lState, void* data, size_t* size) {
|
|
assetscript_t *script = (assetscript_t *)data;
|
|
zip_int64_t bytesRead = zip_fread(
|
|
script->zip, script->buffer, sizeof(script->buffer)
|
|
);
|
|
|
|
if(bytesRead < 0) {
|
|
*size = 0;
|
|
return NULL;
|
|
}
|
|
|
|
*size = (size_t)bytesRead;
|
|
return script->buffer;
|
|
}
|
|
|
|
errorret_t assetScriptDispose(assetscript_t *script) {
|
|
assertNotNull(script, "Script asset cannot be NULL");
|
|
|
|
if(script->zip != NULL) {
|
|
zip_fclose(script->zip);
|
|
script->zip = NULL;
|
|
}
|
|
|
|
errorOk();
|
|
} |