If a nonexistent function is called in a foreach loop, the runtime error thrown returns nothing useful.
e.g.
input:
offending code on line 37:
foreach(collection, missing_function) |
output:
line 0: attempt to call local 'f' (a nil value) |
vs.
input:
offending code on line 37:
missing_function(collection) |
output:
line 37: attempt to call global 'missing_function' (a nil value) |
foreach is likely implemented in lua rather than C as something like
function foreach(c,f) for i in all(c) do f(i) end
so when that errors it doesn't know the name of your variable since it's just argument f to that function.
I don't think this is a bug, but it could be more helpful.
Showing a stacktrace on error would likely help or throwing an error in foreach if the function is nil or not a function.
[Please log in to post a comment]