Re:Lua: the world's most infuriating language?
by kazagistar on Friday October 18, 2013 @11:21AM
(#6571868)
Will you please stop it with the array thing? Lua has no arrays... it has tables. You can use a zero index if you so please, and no one can stop you.
[ Parent
| on HN ]
Re:Lua: the world's most infuriating language?
by anonymoushn on Friday October 18, 2013 @11:59AM
(#6572073)
This is a silly thing to say. Here, let's try to write some code using 1-based indexing:
t = {foo()}
And now with 0-based indexing: function capture_values_internal(idx,t,remaining,val,...)
if remaining == 0 then
return t
else
t[idx]=val
return capture_values_internal(idx+1,t,remaining-1,...)
end
end
function capture_values(...)
return capture_values_internal(0,{},select("#",...),...)
end
t = capture_values(foo())
or function capture_values(...)
local n,t=select("#",...),{...}
for i=0,n do
t[i]=t[i+1]
end
return t
end
t = capture_values(foo())
Gosh, that was easy, I can't wait to use 0-based indexing throughout my program.