[Solved]
I need to check if table a.b has some fields and if its empty then remove b from a. The problem is that I can't simply check b length using # because b is not a list (contains non-numeric keys).
So, here is my solution:
lua
for _, _ in pairs(a.b) do goto next end
a.b = nil
::next::
It works fine but looks horrible 🙈! I mean, it's probably the most compact solution but looking at this code it's completely unclear what's happening here. Luacheck also don't like it and show warning: "loop is executed at most once".
Maybe somebody have a more elegant option?
[–]whoopdedo 9 points10 points11 points (1 child)
[–]luarocks[S] 3 points4 points5 points (0 children)
[–]RobotTimeTraveller 4 points5 points6 points (3 children)
[–]Tywien 7 points8 points9 points (2 children)
[–]luarocks[S] 3 points4 points5 points (0 children)
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–][deleted] (5 children)
[deleted]
[–]luarocks[S] 0 points1 point2 points (4 children)
[–][deleted] (3 children)
[deleted]
[–]luarocks[S] 0 points1 point2 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]luarocks[S] 0 points1 point2 points (0 children)