2 ms·
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.
by kazagistar 13y ago
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.
- anonymoushn 13y agoThis 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.