Closed YahYahDev closed 4 months ago
UPDATE: updated to 12.4 and it still does not work
It's not clear to me what is failing. Could you give an example of what you are seeing vs. what you are expecting?
so basicly im trying to insert values into the "types" table but for some reason it is not applying when i attempt to append it in an "if block" i am unsure of what the cause is but ive tested quite a bit with it and when you make a "print" statement in the "if block" for the "types" table it prints it but as soon as you attempt to "print" outside of the "if block" all changes made are reversed and it reverts to the default table state. i might just be being stupid but i have around 3-4 years of scripting in lua and have never had this issue before and its boggling my mind.
updated the code example to show which if statement was having issues.
i think a better example of what im looking at is this
types = {}
content = parse.GetLines(tags)
for i = 1, #content do
if string.find(content[i], "typedef") then
types[i] = parse.GetBlock(content[i], "^", "%s")
print(types[1]) -- prints what is expected
end
end
print(types[1]) -- prints nil
In your original code example, types
will likely be a table with "holes" (in Lua-speak). That is, there will be some iterations of i
where types[i]
will not be set due to conditional failure. I suspect str.PrintArray()
uses the #
operator, which has undefined behavior if the table has holes in it. lexer:set_word_list()
will also fail for tables with holes in them.
Instead of types[i] = ...
, how about using types[#types + 1] = ...
?
that works! i had no idea that the # operator didnt give you the number of non nil elements gues you learn somthin new every day xD.
i was working on making a module and was trying to use a if condition in a for loop and it could not modify a table from outside the if statement. i did quite alot of testing and it is not the libs im using and the bug persists even if the variables are global or not, im on ta 12.3.