It is reasonable to warn user about "string.sub" usage mistakes such as
that's why in Lua 5.3 string.sub might raise "number has no integer representation" error.
But it appears that math.huge as argument also raises this error.
IMO, the following use cases should be considered as being valid:
string.sub("abc", 2, math.huge)
string.sub("abc", -math.huge, -2)
Yes, I know we could use -1 and 1 values respectively to get the same results,
but infinite values are suitable for the semantic of the function.
It also looks strange that
are OK, but
raise the error.
1) any float position beyond integer range should be treated as infinite value;
2) infinite value should be considered valid despite of not having integer representation.
A small bonus (a hidden surprise for large RAM users): string.rep is unable to repeat 2^31 times.
(Tested on Lua 5.3 on average PC with 16 GB RAM)
> local a = ("a"):rep(2^30); a = a..a; print(#a)
> local a = ("a"):rep(2^31); print(#a)
stdin:1: resulting string too large
[C]: in function 'string.rep'
stdin:1: in main chunk
[C]: in ?