lua-users home
lua-l archive

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


2014-03-25 10:10 GMT+02:00 Tim Hill <drtimhill@gmail.com>:

>On Mar 24, 2014, at 11:21 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> I like the idea of switching metamethods off and on — but dynamically,
>> not lexically scoped. Via routines in the debug library.
>>
>
> Why the debug library? IMHO the debug library shouldn’t really be used for production code .. if it is, then it’s not really a debug library any more except in name.

Because it should be used only when debugging.

Switching metamethods on and off is a highly error-prone
activity, one that can introduce hard-to-find bugs, and In
production code, it should be done in a more visible way,
spelling out each time which metamethod is being switched
for which object.

Something like this:

do  -- `metamethods` must be invisible lower down
local metamethods={}
function disable_metamethod(object,method)
-- save metamethod in `metamethods`
-- set it to nil
end
function enable_metamethod(object,method)
-- set metamethod to what was saved earlier
end
end