[asterisk-users] clarification on gosub, macros and AEL

C.Maj chris at PenguinPBX.com
Tue Oct 15 16:45:01 CDT 2019


I think the WARNING on Gosub() calls from AEL could change to NOTICE; or
at least get more specific, such as "instead of calling Gosub()
directly, please try an AEL macro."

A new AEL keyword to eventually replace "macro", such as "subcontext",
might help clarify things, too.

But it should work fine even with the WARNING messages -- as long as you
are careful* -- because in modern AEL, these two lines make for
equivalent dial plan configuration:

  &some-macro();
  Gosub(some-macro,~~s~~,1);

I prefer the former because it is less to type. Although in some cases,
such as the Dial() application option "b", the ampersand prefix format
won't work, requiring the longer format with ~~s~~ if you want to enter
the macro at the default entry point:

  Dial(PJSIP/1234,,b(some-macro^~~s~~^1));

* However, auto-conversion of macro parameters to local custom variables
is (currently) only handled when entering the default entry point ~~s~~.
So the following AEL example will parse with one WARNING but the Dial()
might not be doing what you expect from just looking at the first line
of the macro definition:

macro mac-test( ext_ ) {
  catch BLEG {
    NoOp(Oops ext_ is blank: ${ext_}. Use ARG1 instead: ${ARG1}.);
    return;
  }
  NoOp(But ext_ is NOT blank at default entry point: ${ext_}.);
  return;
}

context ctx-start {
  _XXXX => {
    &mac-test(${EXTEN}); // default entry, $ext_ will be same as $EXTEN
    Gosub(mac-test,~~s~~,1(${EXTEN})); // ditto, with a WARNING
    Dial(PJSIP/${EXTEN},2,b(mac-test^BLEG^1(${EXTEN}))); // ext_ blank
  }
}

...a corner case like that is why some level of concern should probably
still be raised in the logs on direct Gosub() calls from AEL -- but not
prohibited.


Kind Regards,

-- 
🤠 C. Maj, Technology Captain @ Penguin PBX Solutions
📞 USA Toll Free 1-833-PNGNPBX (1-833-764-6729)
🤙 International & SMS Texting +1.720.32.42.72.9
🐧 https://www.PenguinPBX.com/



More information about the asterisk-users mailing list