According to the wiki, it's the length of the subsection in bytes. Unfortunately, it doesn't work. It doesn't matter if I set the size to 1 or 1000 bytes, I still have access to the whole data object and not just to the subsection I want. The offset value works like it should, but the size value does absolutely nothing.
What code are you using to access the data? The size parameter sets the size that Data:getSize reports, which is the value used when you pass the Data object into various love APIs.
Since it's just a view into the same memory as the original Data object, it doesn't copy the subsection to a new location in memory so nothing stops you from reading past the given offset and size if you're using the FFI or similar tools (similar to how you can read past the end of any allocated array with the FFI).
UnixRoot wrote: ↑Sat Jun 10, 2023 1:31 pm
The wiki states "Data:getFFIPointer will return the original Data object's contents, with the view's offset and size applied"
This is actually the full sentence:
"Data:getString, Data:getPointer and Data:getFFIPointer will return the original Data object's contents, with the view's offset and size applied."
The size is only applicable to one of those (Data:getString) and has no meaning for the getPointer APIs, so I've updated the text there to add "where applicable" at the end of the sentence.
UnixRoot wrote: ↑Sat Jun 10, 2023 1:31 pm
If all the data outside the "view" is still accessible, the wiki text is slightly misleading if you ask me.
slime wrote: ↑Sat Jun 10, 2023 1:20 pm
(similar to how you can read past the end of any allocated array with the FFI).
Of course, but then I only get garbage and not the contents of the array.
When you use the FFI, you are 100% obligated to handle bounds checking yourself no matter what. You cannot rely on crashes or garbage data to detect bounds. Even reading past the end of an array with an explicitly allocated size is not guaranteed to crash or produce garbage, it's just likely to.
So ultimately it's not love's responsibility (and nor is it possible for it to be love's responsibility) to make your own FFI code do its own bounds-checking.
Yeah, an out-of-bounds check isn't a problem, I already do it on my data objects with raw palette indices. I only found the "newDataView" function while browsing the wiki, and it sounded nice.