next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Macaulay2Doc > The Macaulay2 language > using hooks > runHooks

runHooks -- run the hook functions stored in an object

Synopsis

Description

Each function hook in the hash table of hooks associated to key is called with args as its argument or sequence of arguments. The optional argument Strategy can be used to specify which hook should be run. See addHook for where the hooks are stored.

Any other optional argument for runHooks that matches any key in options hook will be passed on to hook. All other options are ignored.

For further explanation and examples of hooks see using hooks.

Code

/usr/share/Macaulay2/Core/option.m2:35:20-40:30: --source code:
  (opts,f) -> args -> (
       -- Common code for functions created with >> to separate options from arguments.
       -- uncurry(f, (new OptionTable from toList select(args, i -> instance(i,Option)), select(args, i -> not instance(i,Option))))
       uncurry(f, override (,args))
       )
  )
| symbol   class              value location of symbol
| ------   -----              ----- ------------------                                   
| f      : FunctionClosure -- ...   /usr/share/Macaulay2/Core/option.m2:35:9-35:10
| opts   : Boolean         -- true  /usr/share/Macaulay2/Core/option.m2:35:4-35:8 
| -- function f:
| /usr/share/Macaulay2/Core/methods.m2:566:58-581:95: --source code:
| runHooks(MutableHashTable, Thing, Thing) := true >> opts -> (store, key, args) -> (
|     store = if store#?key then store#key else (
|         if debugLevel > 1 then printerr("runHooks: no hooks installed for ", toString key); return );
|     alg := if opts.?Strategy then opts.Strategy;
|     type := class alg;
|     -- if Strategy is not given, run through all available hooks
|     if alg === null then scan(reverse store.HookPriority, alg -> (
|             result := runHook(store.HookAlgorithms#alg, key, alg, args, opts ++ { Strategy => alg });
|             if not instance(result, Nothing) then break result)) else
|     -- if Strategy is given, and it is among the known strategies, run only that hook
|     if store.HookAlgorithms#?alg  then runHook(store.HookAlgorithms#alg,  key, alg,  args, opts) else
|     -- otherwise, if the class of alg is a known strategy, run only that hook
|     if store.HookAlgorithms#?type then runHook(store.HookAlgorithms#type, key, type, args, opts) else
|     -- otherwise, give an error with the list of possible strategies
|     error("unrecognized Strategy => '", toString alg, "' for ", toString key, newline,
|         "  available strategies are: ", demark_", " \\ toExternalString \ new List from store.HookPriority))

See also

Ways to use runHooks :

For the programmer

The object runHooks is a method function with options.