data:extend({nil}) does not error, but causes the NEXT prototype to fail to register
data:extend({nil}) does not error, but causes the NEXT prototype to fail to register
That is to say, if I have prototypes A, B, C, and D, and data:extend({a, b, c, d}), if b is nil, there is no error thrown at any point, but c also fails to be created in the game.
Re: data:extend({nil}) does not error, but causes the NEXT prototype to fail to register
Code: Select all
function data.extend(self, otherdata)
if type(otherdata) ~= table_string or #otherdata == 0 then
error("Invalid prototype array " .. serpent.block(otherdata, {maxlevel= 1}))
end
for _, e in ipairs(otherdata) do
Re: data:extend({nil}) does not error, but causes the NEXT prototype to fail to register
At the very least, "nil" should throw an error as a prototype value, the way random garbage does.Nexela wrote: ↑Thu Oct 18, 2018 1:38 amNot a bug in the sense that it is doing what ipairs does by stopping iteration at the first nil. I wouldn't be surprised if rseding changes it to use pairs though, because pairs always worksCode: Select all
function data.extend(self, otherdata) if type(otherdata) ~= table_string or #otherdata == 0 then error("Invalid prototype array " .. serpent.block(otherdata, {maxlevel= 1})) end for _, e in ipairs(otherdata) do
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: data:extend({nil}) does not error, but causes the NEXT prototype to fail to register
You're basically calling data:extend{[1]=a,[2]=b,[4]=d}. Lua doesn't make a difference between you explicitly setting [3] to nil or if [3] just accidentially happens to be nil, same as for [5] and following.
Changing to pairs() sounds like a reasonable solution.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: data:extend({nil}) does not error, but causes the NEXT prototype to fail to register
Thanks for the report however I don't consider this worth adding a custom error for.
Currently even the "type" checks in data:extend have a measurable overhead to how long it takes prototypes to load. Since the *extreme* normal use-case is the inputs are correct I think it's fine if it doesn't handle "nicely" when they aren't.
Currently even the "type" checks in data:extend have a measurable overhead to how long it takes prototypes to load. Since the *extreme* normal use-case is the inputs are correct I think it's fine if it doesn't handle "nicely" when they aren't.
If you want to get ahold of me I'm almost always on Discord.