Re: [asterisk-users] AEL switch & case

2022-08-31 Thread Antony Stone
Replying to list this time...

On Wednesday 31 August 2022 at 12:47:13, aster...@phreaknet.org wrote:

> On 8/31/2022 6:32 AM, Antony Stone wrote:
> > Hi.
> > 
> > I think I've discovered a bug in either the implementation or the
> > documentation of the AEL switch command.
> > 
> > https://wiki.asterisk.org/wiki/display/AST/AEL+Conditionals gives an
> > example of using switch, and states at the bottom:
> > 
> > "Neither the switch nor case values are wrapped in $[ ]; they can be
> > constants, or ${var} type references only."
> > 
> > However, I've run into a problem, which can be demonstrated by the simple
> > context:
> > 
> > context SwitchTest {
> >s => {
> >  Set(FortyTwo=42);
> >  Set(SixByNine=54);
> >  switch(${SixByNine}) {
> >case 123:
> >  NoOp(123);
> >  break;
> >case ${FortyTwo}:
> >  NoOp(${FortyTwo});
> >  break;
> >  }
> >}
> > }

> > Am I misundertanding "they can be constants, or ${var} type references
> > only."?
> 
> I don't think this is a bug. ${FortyTwo} is not defined when the AEL
> dialplan is transpiled into dialplan. It only gets set at runtime.

Agreed, however that is surely a perfectly reasonable "${var} type reference"?

> This might work if you made FortyTwo a global variable, which would be
> available when this gets parsed.

Quite possibly, but I would expect switch() to work in the same way as 
multiple if() statements:

switch(${a}) {
  case ${b}: NoOp(${b} matches); break;
  case ${c}: NoOp(${c} matches); break;
// etc
}

should be equivalent to:

if(${a}=${b}) NoOp(${b} matches);
if(${a}=${c}) NoOp(${c} matches);
// etc

The latter works perfectly well, no matter when ${b} and ${c} are assigned 
their values.

I've adjusted my dialplan to use multiple if()s, but I still thik that either 
the implementation or the documentation of switch is incorrect.


Antony.

-- 
I bought a book on memory techniques, but I've forgotten where I put it.

   Please reply to the list;
 please *don't* CC me.

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

[asterisk-users] AEL switch & case

2022-08-31 Thread Antony Stone
Hi.

I think I've discovered a bug in either the implementation of the 
documentation of the AEL switch command.

https://wiki.asterisk.org/wiki/display/AST/AEL+Conditionals gives an example 
of using switch, and states at the bottom:

"Neither the switch nor case values are wrapped in $[ ]; they can be 
constants, or ${var} type references only."

However, I've run into a problem, which can be demonstrated by the simple 
context:

context SwitchTest {
  s => {
Set(FortyTwo=42);
Set(SixByNine=54);
switch(${SixByNine}) {
  case 123:
NoOp(123);
break;
  case ${FortyTwo}:
NoOp(${FortyTwo});
break;
}
  }
}

This gets converted by AEL into:

[ Context 'SwitchTest' created by 'pbx_ael' ]
  's' =>1. MSet(~~EXTEN~~=${EXTEN})
2. Set(FortyTwo=42)
3. Set(SixByNine=54)
4. Goto(sw_5410_${SixByNine},10)
5. NoOp(Finish switch_SwitchTest_5410)
  'sw_5410_' => 10. Goto(sw_5410_.,10)
11. Goto(s,5)
  'sw_5410_123' =>  10. NoOp(123)
11. Goto(s,5)
  '_sw_5410_.' =>   10. Goto(s,5)

So, there was no implementation of the "case ${FortyTwo}" match.

Am I misundertanding "they can be constants, or ${var} type references only."?


Antony.

-- 
Normal people think "If it ain't broke, don't fix it".
Engineers think "If it ain't broke, it doesn't have enough features yet".

   Please reply to the list;
 please *don't* CC me.

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users