B.58. Macro()

Executes a previously defined macro.
Macro(macroname[,arg1[,arg2[,...]]])
Executes a macro defined in the context macro-macroname by handing the channel over to the s extension in the macro and returning after the macro has finished running.
The called extension, context and priority are passed to the macro in the variables ${MACRO_EXTEN}, ${MACRO_CONTEXT} and ${MACRO_PRIORITY}. The arguments are passed to the macro in ${ARG1}, ${ARG2}, and so on.
Macro() returns -1 if any step in the macro returns -1, otherwise it returns 0. If the variable ${MACRO_OFFSET} is set when the macro finishes, the application will continue executing at priority n+1+MACRO_OFFSET if it exists, otherwise it will continue at n+1.
If Goto() is called from within the macro, macro execution ends and the call continues in the priority specified in Goto().
; define a macro that counts down from the provided value:
[macro-countdown]
exten => s,1,Set(COUNT=${ARG1})
exten => s,n,While($[ ${COUNT} > 0])
exten => s,n,SayNumber(${COUNT})
exten => s,n,Set(COUNT=$[ ${COUNT} - 1 ])
exten => s,n,EndWhile()

[default]
exten => 123,1,Macro(countdown,3)   ; call the macro "countdown" with ARG1=3
exten => 124,1,Macro(countdown,5)   ; call the macro "countdown" with ARG1=5

Note

Internal help for this application in Asterisk 1.4:
  -= Info about application 'Macro' =- 

[Synopsis]
Macro Implementation

[Description]
  Macro(macroname|arg1|arg2...): Executes a macro using the context
'macro-<macroname>', jumping to the 's' extension of that context and
executing each step, then returning when the steps end. 
The calling extension, context, and priority are stored in ${MACRO_EXTEN}, 
${MACRO_CONTEXT} and ${MACRO_PRIORITY} respectively.  Arguments become
${ARG1}, ${ARG2}, etc in the macro context.
If you Goto out of the Macro context, the Macro will terminate and control
will be returned at the location of the Goto.
If ${MACRO_OFFSET} is set at termination, Macro will attempt to continue
at priority MACRO_OFFSET + N + 1 if such a step exists, and N + 1 otherwise.
WARNING: Because of the way Macro is implemented (it executes the priorities
         contained within it via sub-engine), and a fixed per-thread
         memory stack allowance, macros are limited to 7 levels
         of nesting (macro calling macro calling macro, etc.); It
         may be possible that stack-intensive applications in deeply nested macros
         could cause asterisk to crash earlier than this limit.
diff output to internal help in Asterisk 1.2:
22,23c22,23
<          may be possible that stack-intensive applications in deeply nested macros
<          could cause asterisk to crash earlier than this limit.
---
>          may be possible that stack-intensive applications in deeply nested
>          macros could cause asterisk to crash earlier than this limit.