lua-users home
lua-l archive

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



> On Sep 13, 2023, at 10:25 AM, Mouse <mouse@Rodents-Montreal.ORG> wrote:
> 
>> You can already solve it with a wrapper, something like;
> 
>> local function deprecated(fn, msg)
>>  return function(...)
>>    print(msg)
>>    return fn(...)
>>  end
>> end
> 
> Sure, but that warns when the function is called, not when its name is
> used.  If that's what you want, fine, but if I mark soemthing
> deprecated, I expect/want a warning when the name is used (one warning
> per use at most), not each time the function it resolves to is called.
> 

Deprecation in other languages is handled at compile time, which isnt really an option for dynamic languages like Lua. Since in Lua functions do not have a name, then its meaningless to ask “when its name is used”.

The previous suggestion (using a deprecated() function to wrap the deprecated function) can trivially be extended to only generate one warning when the function is first called. That seems reasonable to me. After all, what does “deprecated” mean? Shouldn’t it mean “this function should not be used any more” ? .. which is exactly what the dynamic warming wrapper checks for.

—TIm