file.write_bytes fix

This commit is contained in:
Onran 2024-02-27 10:45:38 +09:00 committed by GitHub
parent a75d578aea
commit f2dff183f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -140,25 +140,21 @@ int l_file_write_bytes(lua_State* L) {
int i = 1;
while(lua_next(L, bytesIndex) != 0) {
if(i == len) {
if(i >= len) {
break;
}
if(lua_isnumber(L, -1)) {
const int byte = lua_tointeger(L, -1);
const int byte = lua_tointeger(L, -1);
if(byte < 0 || byte > 255) {
return luaL_error(L, "byte '%i' at index '%i' is less than 0 or greater than 255", byte, i);
}
bytes.push_back(byte);
lua_pop(L, 1);
i++;
} else {
return luaL_error(L, "number expected at index '%i' (got %s)", i, lua_typename(L, lua_type(L, -1)));
if(byte < 0 || byte > 255) {
return luaL_error(L, "byte '%i' at index '%i' is less than 0 or greater than 255", byte, i);
}
bytes.push_back(byte);
lua_pop(L, 1);
i++;
}
lua_pushboolean(L, files::write_bytes(path, &bytes[0], len));