lua-users home
lua-l archive

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


>> local function get_suffix_of_length(str, len)
>>  return str:sub(-len)
>> end
>> 
>> get_suffix_of_length(s, math.huge)  -- Easily understandable
>> get_suffix_of_length(s, -1)  -- What does "the suffix of length (-1)" mean?
> 
> If the code is expected to run under Lua 5.3, then why not
> 
>   get_suffix_of_length(s,math.maxinteger) --?
> 
> And if you want to run it under previous versions:
> 
>   get_suffix_of_length(s,math.maxinteger or -1)
> 
> which shows intent *and* is backwards compatible (yes, the -1 looks odd).
> 
> -spc

I do not even know Lua "trim edges" that that.
I think exact length is more readable, and skip this "feature"

> get_suffix_of_length(s, #s)