diff --git a/src/logic/scripting/lua/lua_custom_types.cpp b/src/logic/scripting/lua/lua_custom_types.cpp index 03162449..2983e1b1 100644 --- a/src/logic/scripting/lua/lua_custom_types.cpp +++ b/src/logic/scripting/lua/lua_custom_types.cpp @@ -105,11 +105,14 @@ static int l_bytearray_meta_newindex(lua::State* L) { return 0; } auto& data = buffer->data(); - auto index = tointeger(L, 2)-1; - if (static_cast(index) > data.size()) { + auto index = static_cast(tointeger(L, 2)-1); + auto value = tointeger(L, 3); + if (index >= data.size()) { + if (index == data.size()) { + data.push_back(static_cast(value)); + } return 0; } - auto value = tointeger(L, 3); data[index] = static_cast(value); return 0; }