fix canvas:set_data
This commit is contained in:
parent
5436b98f3b
commit
66bb734a4e
@ -45,7 +45,7 @@ local canvas_ffi_buffer_size = 0
|
|||||||
local _ffi = ffi
|
local _ffi = ffi
|
||||||
function __vc_Canvas_set_data(self, data)
|
function __vc_Canvas_set_data(self, data)
|
||||||
if type(data) == "cdata" then
|
if type(data) == "cdata" then
|
||||||
self:_set_data(tostring(_ffi.cast("uintptr_t", data)))
|
self:_set_data(tostring(_ffi.cast("uintptr_t", data.bytes)), data.size)
|
||||||
end
|
end
|
||||||
local width = self.width
|
local width = self.width
|
||||||
local height = self.height
|
local height = self.height
|
||||||
@ -60,7 +60,7 @@ function __vc_Canvas_set_data(self, data)
|
|||||||
for i=0, size - 1 do
|
for i=0, size - 1 do
|
||||||
canvas_ffi_buffer[i] = data[i + 1]
|
canvas_ffi_buffer[i] = data[i + 1]
|
||||||
end
|
end
|
||||||
self:_set_data(tostring(_ffi.cast("uintptr_t", canvas_ffi_buffer)))
|
self:_set_data(tostring(_ffi.cast("uintptr_t", canvas_ffi_buffer)), data.size)
|
||||||
end
|
end
|
||||||
|
|
||||||
local ipairs_mt_supported = false
|
local ipairs_mt_supported = false
|
||||||
|
|||||||
@ -220,6 +220,14 @@ static int l_set_data(State* L) {
|
|||||||
|
|
||||||
if (lua::isstring(L, 2)) {
|
if (lua::isstring(L, 2)) {
|
||||||
auto ptr = reinterpret_cast<ubyte*>(std::stoull(lua::tostring(L, 2)));
|
auto ptr = reinterpret_cast<ubyte*>(std::stoull(lua::tostring(L, 2)));
|
||||||
|
int len = lua::touinteger(L, 3);
|
||||||
|
if (len < image.getDataSize()) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"data size mismatch expected " +
|
||||||
|
std::to_string(image.getDataSize()) + ", got " +
|
||||||
|
std::to_string(len)
|
||||||
|
);
|
||||||
|
}
|
||||||
std::memcpy(data, ptr, image.getDataSize());
|
std::memcpy(data, ptr, image.getDataSize());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user