lua-users home
lua-l archive

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


2014-03-02 21:21 GMT+02:00 Coroutines <coroutines@gmail.com>:

> As I was telling Mr. Laurie, string.sub() is fine but I very much
> disagree with string.find()/string.match() moving the starting index
> up.
>
> The problem is still there in 5.2:
> http://www.lua.org/source/5.2/lstrlib.c.html#str_find_aux

It's not a problem, it is documented behaviour, and has been
like that for many years. Existing code may well rely on it,
so it is not going to be changed because some people
disagree.

If you don't like it, it is particularly easy to change it yourself.

local string_find = string.find
string.find = function (s, pattern , init , plain)
   if init and init+#s<1 then error "string.find: invalid index"
   else return string_find (s, pattern , init , plain)
   end
end