# # # patch "ChangeLog" # from [ed14b3885b18f12d320b554f75c02329a7b5cbb3] # to [b0c9e82bdcfe3122776d6bae9d39323e34cd2351] # # patch "monotone.texi" # from [12e4a3077e1ad37937308c926a7a76d263d0c4e8] # to [d83884e58124f96aba1407ae9fa444b29d4ada93] # ============================================================ --- ChangeLog ed14b3885b18f12d320b554f75c02329a7b5cbb3 +++ ChangeLog b0c9e82bdcfe3122776d6bae9d39323e34cd2351 @@ -1,3 +1,8 @@ +2006-06-14 Alex Queiroz + + * monotone.texi: Added a trick about reusing code from the default + hooks using Lua closures. + 2006-06-13 Derek Scherger * cmd_list.cc (ls_changed): roster friendly rewrite using existing ============================================================ --- monotone.texi 12e4a3077e1ad37937308c926a7a76d263d0c4e8 +++ monotone.texi d83884e58124f96aba1407ae9fa444b29d4ada93 @@ -17,6 +17,7 @@ Copyright 2005 Derek Scherger Copyright 2005 Daniel Carosone Copyright 2006 Jeronimo Pellegrini +Copyright 2006 Alex Queiroz All rights reserved Licensed to the public under the terms of the GNU FDL (>= 1.1). See the file COPYING for details @@ -6791,12 +6792,31 @@ By specifying @address@hidden you can automatically load all the files contained into @var{directory}. +Monotone provides some default hooks, see @ref{Default hooks} for their +complete source. When writing new hooks, it may be helpful to reuse some code +from the default ones. Since Lua is a lexically scoped language with closures, +this can be achieved with the following code: + address@hidden address@hidden +do + local old_hook = default_hook + function default_hook(arg) + if not old_hook(arg) then + -- do other stuff + end + end +end address@hidden group address@hidden smallexample + +Now the default hook is trapped in a variable local to this block, and can +only be seen by the new hook. Since in Lua variables default to the global +scope, the new hook is seen from inside monotone. + Monotone also makes available to hook writers a number of helper functions exposing functionality not available with standard lua. -For the complete source of the default hooks see @ref{Default -hooks}. - @menu * Hooks:: All hooks called by monotone. * Additional Lua Functions:: Extra functionality available to hook writers.