luanti-org/luanti
View on GitHubVoxelArea: `iter` / `iterp` should safely handle "invalid" areas
Open
#17,065 opened on Mar 26, 2026
@ Script APIRequest / Suggestiongood first issue
Repository metrics
- Stars
- (13,341 stars)
- PR merge metrics
- (PR metrics pending)
Description
The following code
core.register_chatcommand("test_va", {
func = function(name, param)
local p1, p2 = vector.new(0,16,0), vector.new(15,31,15)
local va = VoxelArea(p1, p2)
local vmax = va:getVolume() -- this is 4096
for i in va:iter(0, 16, 0, 15, 0, 15) do
if i < 0 or i > vmax then
return false, ("index %d is invalid"):format(i)
end
end
return true
end
})
currently fails as iter returns nonsense and eventually even out-of-range values.
The "mistake" by the caller is that y=0 is not even in the area. However I think it would be more useful if the API handled such usage safely and correctly.
Wanted behavior (with the values from the example code):
va:iter(0, 10, 0, 15, 20, 15)is equivalent tova:iter(0, 16, 0, 15, 20, 15)va:iter(0, 10, 0, 15, 12, 15)produces no results