lua-users home
lua-l archive

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


rrthomasrr wrote:
> 
> Looking at the source, str_find indeed simply looks to see whether it
> has a fourth argument.

Sigh, another example of the arg handling ad hockery...

> This is rather annoying, as in some other cases where it's nice to be
> able to pass "nil" instead of omitting the argument.

You say it...

> It would not be contrary to the 4.0 manual to change this behaviour
>[...]
> Could this be done?

Sure, it _could_.  One could fix this place by converting the test
lua_gettop(L)>3  to  luaL_opt_int(L,3,0)==1,  or one could finally
start thinking about cleaning up argument handling in the C-API...


>[...] is there any way around this?

function strfind(a,b,c,d)
  c = c or 1  -- c has a similar problem...
  if d then
    return %strfind(a,b,c,d)
  else
    return %strfind(a,b,c)
  end
end

Ciao, ET.