[asterisk-dev] [Code Review] Add stack-like functions for manipulating comma-separated lists in the dialplan

Terry Wilson twilson at digium.com
Wed Apr 22 09:14:33 CDT 2009



> On 2009-04-22 01:16:09, Tilghman Lesher wrote:
> > /trunk/funcs/func_strings.c, line 321
> > <http://reviewboard.digium.com/r/230/diff/1/?file=4328#file4328line321>
> >
> >     I think a much more logical syntax would be:
> >     Set(PUSH(array)=one,two,three)

It would, but you lose the ability to have PUSH() actually return the array, so you have to do the PUSH() then read the variable.  That's fine, I suppose, I was just trying to make it possible to streamline dialplan commands where possible.


> On 2009-04-22 01:16:09, Tilghman Lesher wrote:
> > /trunk/funcs/func_strings.c, line 284
> > <http://reviewboard.digium.com/r/230/diff/1/?file=4328#file4328line284>
> >
> >     You have POP() in this example, while I think you meant to have SHIFT().

oops!  fixed.


- Terry


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://reviewboard.digium.com/r/230/#review732
-----------------------------------------------------------


On 2009-04-22 00:18:58, Terry Wilson wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://reviewboard.digium.com/r/230/
> -----------------------------------------------------------
> 
> (Updated 2009-04-22 00:18:58)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> Currently there exists the ARRAY() dialplan function for setting multiple variables to the values in a comma-separated list.  This is only useful if the size of the list is known beforehand.  This patch adds the functions SHIFT(), POP(), and PUSH() for dealing with comma-separated lists of unknown length.  PUSH() and POP() add and remove a value to the end of the list (top of the stack), while SHIFT() removes a value from the front of a list.
> 
> I originally found a need for this when working on my calendaring branch.  I needed to be able to return a list of attendees to the dialplan and to be able to iterate over them.  As an example, I can now do something like:
> exten => s,1,Set(attendees=${EVENT_ATTENDEES()})
> exten => s,n,While($[${SET(attendee=${SHIFT(attendees)})}])
> exten => s,n,NoOp(Attendee is ${attendee})
> exten => s,n,EndWhile
> 
> instead of having to mess with using CUT(), maintaining a count for the offset, etc.  From what I can tell perl, python, and php all consider push and pop to operate on the "right-hand" side of a list.
> 
> 
> Diffs
> -----
> 
>   /trunk/funcs/func_strings.c 189273 
> 
> Diff: http://reviewboard.digium.com/r/230/diff
> 
> 
> Testing
> -------
> 
> I've tested most of the cases I can think of, like pushing to non-existent variables, pushing multiple values, shift and pop with a variable with a single or multiple entries, etc.
> 
> 
> Thanks,
> 
> Terry
> 
>




More information about the asterisk-dev mailing list