What you're experiencing is argument trimming.
Let's run through what you have and explain what's happening when the Lua parses it.
-- T is equal to 1, 2, 3, (NOTHING)
-- Therefore we should trim the nil from the end.
t = {1, 2, 3, nil};
-- T is equal to 1, nil, 3, 4
-- We have something on the end after nil, so we'll count nil as an element.
t = {1, nil, 3, 4};
The same happens in functions, too. Which can be a bit of a hassle, but sometimes handy. Take the following for example:
-- We declare a function with x and y as it's parameters.
-- It expects x and y.
function Vector(x, y) print(x, y); end
-- But... If we add something unexpected:
Vector("x", "y", "Variable");
-- We'll encounter some unexpected behaviour. We have no use for the "Variable" we handed it.
-- So we just wont use it.
Same goes for the other way around. If you hand in a function that requires X, Y, and Z but you hand it X and Y, you'll be passing nil instead of Z.
Refer to this answer here, because you can indeed represent nil within a table using the following:
-- string int nil
t = {"var", "1", "nil"};
t = table.pack(1, 2, 3, nil) print(t.n)
. – Orella