lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

table.move forbids a negative index on the source index, but not the 
destination. Why the restriction? And why not restrict both source and 
destination? There's a comment about overflow, but I don't see where it would 
be a problem. Perhaps the statement 'n = e - f + 1' but isn't it possible to 
detect overflow? And why not check for overflow on the destination too? 

  > table.move({"a","b","c"},1,3, math.maxinteger*2+1,{})
  > table.move(t,1,math.maxinteger*2+1, -1,{})

(Pretend that the second one won't run out of memory.)
Not to mention overflow problems when the source index is close to the 

Some of the functions in the table library permit negative indexes even though 
the documentation officially only works on sequences.

  > print(table.unpack({"a","b","c",[-1]="x"}, -1))
  x   nil a   b   c

Should the documentation state that some functions allow non-sequences? Should 
out-of-bound indexes always be checked? 

tom <>