fix canvas:set_data

This commit is contained in:
MihailRis
2025-11-26 22:46:43 +03:00
parent 5436b98f3b
commit 66bb734a4e
2 changed files with 10 additions and 2 deletions
@@ -220,6 +220,14 @@ static int l_set_data(State* L) {
if (lua::isstring(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());
return 0;
}