love2d / love

LÖVE is an awesome 2D game framework for Lua.
https://love2d.org
Other
4.84k stars 388 forks source link

byteData:clone is a nil function #1754

Closed EngineerSmith closed 2 years ago

EngineerSmith commented 2 years ago

I cannot clone a byteData object in love 11.3, the function is nil.

Repo:

local byteData = love.data.newByteData(196)
local cloned = byteData:clone() -- attempt to call method 'clone' (a nil value)

Links: https://love2d.org/wiki/ByteData https://love2d.org/wiki/Data:clone

zorggn commented 2 years ago

Looks like this might be the culprit, ByteData's clone method isn't exposed in the wrapper: https://github.com/love2d/love/blob/main/src/modules/data/wrap_ByteData.cpp#L34-L37

static const luaL_Reg w_ByteData_functions[] =
{
    { 0, 0 }
};

(Also, the wiki implies that clone also exists for the abstract Data type too, but looking at wrap_data.cpp, that doesn't seem to be the case - this might not be an issue though.)

EngineerSmith commented 2 years ago

Temp solution to this issue to clone a byteData:

local clone = function(byteData)
  return love.data.newByteData(byteData:getString(), 0, byteData:getSize())
end

This solution is twice as fast than a cpp(ffi lib) memcpy in my benchmarks