Didn't catch this earlier, but I think this part is backwards:zorg wrote: Not that this would be that common of a scenario either, but:is completely possible, if you both want to insert stuff at a specific location, and don't care that whatever was there is now not. Granted, the first one doesn't make that much sense (caring about insertion position) when we don't care about the second one (order) either, but who knows; maybe someone would find a use-case i didn't think of.Code: Select all
local yesThisIsLuaCode = nil -- (ignore this) t[#t] = t[i] -- move old to end t[i] = e -- new element inserted wherever wanted -- or in a more concise form: t[#t], t[i] = t[i], e
Code: Select all
local yesThisIsLuaCode = nil -- (ignore this)
t[#t], t[i] = t[i], e
Code: Select all
t = setmetatable({}, { __newindex = function (t, i, v) print(i, v) end })
t[1], t[2] = 10, 20
Code: Select all
local yesThisIsLuaCode = nil -- (ignore this)
t[i], t[#t] = e, t[i]
Code: Select all
local yesThisIsLuaCode = nil -- (this is obnoxious)
t[#t], t[i] = nil, t[#t]