Blob:getString takes an optional byte range;
@@ -24,7 +24,14 @@ static int l_lovrBlobGetSize(lua_State* L) {
static int l_lovrBlobGetString(lua_State* L) {
Blob* blob = luax_checktype(L, 1, Blob);
- lua_pushlstring(L, blob->data, blob->size);
+
+ uint32_t offset = luax_optu32(L, 2, 0);
+ lovrCheck(offset < blob->size, "Blob byte offset must be less than the size of the Blob");
+
+ uint32_t length = luax_optu32(L, 3, blob->size - offset);
+ lovrCheck(length <= blob->size - offset, "Blob:getString range overflows the length of the Blob");
+
+ lua_pushlstring(L, (char*) blob->data + offset, length);
return 1;
}
