Log In  

I noticed that deli(tbl,0) doesn't seem to affect tbl[0] at all. Is this intended behavior? Was just sorta curious since I haven't had any issues with deli() otherwise

P#104979 2022-01-13 06:06 ( Edited 2022-01-13 06:12)

Yeah, deli with a zero or negative index seems to just be ignored. Since those cases don't appear to be documented it's hard to say whether it's the intended behaviour or not--I'd prefer an error message telling me my index was out of range personally--but it seems like reasonable behaviour at least. Deli will normally reorder the array to eliminate any [nil] values in the middle and since lua arrays are 1-based it will re-order so the first element is at index 1.

In that context, deleting the element at index 0 or just ignoring it and doing nothing are functionally equivalent, at least as far as the other array handling functions are concerned: they all assume 1-based arrays so they'll never see the element at index 0 anyway.

You could always override the default deli with your own version which works on 0-based arrays but it'll use up tokens and probably be less efficient. Unless you really need 0-based arrays it's almost certainly not worth it and just easier to stick to 1-based arrays.

P#105004 2022-01-13 17:30
1

It seems like intended behaviour!

Array-like tables use continuous integer indices starting at 1. This is fundamental to the operation of add, all, #, deli, etc.

When 0 is used as index, it is treated the same any regular mapping index, like a string. It does not change the 1-based behaviours.

pal is the one exception that will consider index 0 to replace palette entry 0.

P#105011 2022-01-13 17:48

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-19 13:46:21 | 0.007s | Q:15