Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made love.data.newDataView size arg optional #2088

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

EngineerSmith
Copy link
Contributor

I got annoyed that I had to keep calculating the size lua side when making a new dataview. So, this change makes the 3rd arg [size], optional and is calculated as love.data.newByteData calculates the default size when calling love.data.newByteData(someData) this line

I made this change on github directly; and so I haven't tested the change. I'll add a comment once I've tested the build to ensure it works as expected.

Example usage:

local data = love.data.newByteData(200)
local offset = 100

-- Change:
local dataview = love.data.newDataView(data, offset)
-- Previously:
local dataview = love.data.newDataView(data, offset, data:getSize() - offset)

@slime73
Copy link
Member

slime73 commented Jul 29, 2024

The change seems reasonable to me, but I'm curious what sort of situations you were running into where you wanted to use all the remaining size after an offset

@EngineerSmith
Copy link
Contributor Author

Right now I'm making a chunk of a save file; I precalculated the chunk size/length for all the data I have to insert into the chunk; so I'm treating it like a write to a file which moves the cursor/position along. I've ran into this previously when working with dataviews. So, I thought it would be a "nice to have" than having to store the offset in a different variable.

-- When quickly prototyping, I don't want to come back and fix this mess. When I can add the source change to handle it for me as I add more to the offset
love.data.newDataView(data, foo + x + y + z, data:getSize() - (foo + x + y + z))

I tested it; with this code and looks good.

local data = love.data.newByteData(200)
local offset = 50

local dv = love.data.newDataView(data, offset)

print(tostring(dv:getSize() == 150), dv:getSize()) -- true   150

@EngineerSmith EngineerSmith marked this pull request as ready for review July 29, 2024 19:56
@slime73
Copy link
Member

slime73 commented Jul 29, 2024

Makes sense, thanks!

@slime73 slime73 merged commit 8d4be76 into love2d:main Jul 29, 2024
7 checks passed
@EngineerSmith EngineerSmith deleted the patch-1 branch July 30, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants