[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Behavior of utf8.offset overflow
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 24 Apr 2017 13:32:47 -0300
> (Side note: string.byte is a bit funny in that it returns _no value_
> in case of overflow (not nil)
>
> > string.byte("hello", 10)
> > type(string.byte("hello", 10))
> stdin:1: bad argument #1 to 'type' (value expected)
> stack traceback:
> [C]: in function 'type'
> stdin:1: in main chunk
> [C]: in ?
> > x = string.byte("hello", 10); print(x)
> nil
>
> It's not clear to me what are the criteria for functions to return no
> value versus nil -- as seen above, string.find returns an explicit
> nil.)
string.byte has a variable number of returns:
> string.byte("hello", 3, 5)
--> 108 108 111
> string.byte("hello", 5, 5)
--> 111
> string.byte("hello", 6, 5)
--> (nothing)
If there are no results to be returned, it returns nothing.
-- Roberto