[Home]

Summary:ASTERISK-02515: app_vareval - allows the evaluation of dynamically built variables
Reporter:scaredycat (scaredycat)Labels:
Date Opened:2004-10-01 09:44:24Date Closed:2011-06-07 14:05:02
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Applications/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) app_vareval.tar.gz
Description:Allows you to evaluate:

${MYVAR1}${MYVAR2}

ie:

if MYVAR1 = LINE and MYVAR2 = 1 then

VarEVAL(RETURNVAR=${MYVAR1}${MYVAR2})

will place the VALUE of what is in the variable LINE1 into RETURNVAR



Comments:By: twisted (twisted) 2004-10-01 11:16:07

Does the current applicaiton Eval() not do this?

By: scaredycat (scaredycat) 2004-10-01 12:14:24

No,

I'm not entirely sure what eval is used for, and I didn;t want to change it since people may be using it for whatever is was designed for:

exten => s,1,SetVar(MONKEY_PIGS=10)
exten => s,2,SetVar(POOP=MONKEY)
exten => s,3,SetVar(BLAH=PIGS)
exten => s,4,SetVar(VAR_1=${POOP}_${BLAH})
exten => s,5,VarEval(XXX=${VAR_1})
exten => s,6,Eval(CHEESE=${VAR_1})
exten => s,7,NOOP(${CHEESE})
exten => s,8,NOOP(${XXX})
exten => s,9,Hangup

   -- Executing SetVar("SIP/2205-fc6c", "MONKEY_PIGS=10") in new stack
   -- Executing SetVar("SIP/2205-fc6c", "POOP=MONKEY") in new stack
   -- Executing SetVar("SIP/2205-fc6c", "BLAH=PIGS") in new stack
   -- Executing SetVar("SIP/2205-fc6c", "VAR_1=MONKEY_PIGS") in new stack
   -- Executing VarEval("SIP/2205-fc6c", "XXX=MONKEY_PIGS") in new stack
   -- Executing Eval("SIP/2205-fc6c", "CHEESE=MONKEY_PIGS") in new stack
Eval Result  :    -- Executing NoOp("SIP/2205-fc6c", "MONKEY_PIGS") in new stack
VarVAL Result:    -- Executing NoOp("SIP/2205-fc6c", "10") in new stack

edited on: 10-01-04 12:20

By: twisted (twisted) 2004-10-01 12:27:07

Seems to me like it does..

   -- Executing SetVar("IAX2/production@production/3", "MYVAR1=Line") in new stack
   -- Executing SetVar("IAX2/production@production/3", "MYVAR2=1") in new stack
   -- Executing NoOp("IAX2/production@production/3", "MYVAR1 = Line and MYVAR2= 1") in new stack
   -- Executing Eval("IAX2/production@production/3", "RETURNVAR=Line1") in new stack
   -- Executing NoOp("IAX2/production@production/3", "RETURNVAR = Line1") in new stack

By: twisted (twisted) 2004-10-01 12:30:05

sorry, forgot to paste the logic

exten => 1000,1,SetVar(MYVAR1=Line)
exten => 1000,2,SetVar(MYVAR2=1)
exten => 1000,3,NoOp(MYVAR1 = ${MYVAR1} and MYVAR2 = ${MYVAR2})
exten => 1000,4,Eval(RETURNVAR=${MYVAR1}${MYVAR2})
exten => 1000,4,NoOp(RETURNVAR = ${RETURNVAR})

By: scaredycat (scaredycat) 2004-10-01 13:14:58

Look at what you are doing and the result you get:

Command:

exten => 1000,4,NoOp(RETURNVAR = ${RETURNVAR})

Result:

-- Executing NoOp("IAX2/production@production/3", "RETURNVAR = Line1") in new stack


with VarEval the **CONTENT** of the var Line1 would be returned not the variable name

eg:

exten => s,1,SetVar(MYVAR_1=10)
exten => s,2,SetVar(POOP=MYVAR)
exten => s,3,SetVar(BLAH=1)

exten => s,4,SetVar(VAR_1=${POOP}_${BLAH})

VAR_1 now equals "MYVAR_1"

exten => s,5,VarEval(MYRESULT=${VAR_1})


MYRESULT now equals 10 (ie the VALUE of MYVAR_1)

exten => s,8,NOOP(${MYRESULT})
VarVAL Result: -- Executing NoOp("SIP/2205-fc6c", "10") in new stack

edited on: 10-01-04 13:17

By: twisted (twisted) 2004-10-01 15:31:01

Simply doublewrap it

exten => 1000,1,SetVar(Line1=200)
exten => 1000,2,SetVar(MYVAR1=Line)
exten => 1000,3,SetVar(MYVAR2=1)
exten => 1000,4,NoOp(MYVAR1 = ${MYVAR1} and MYVAR2 = ${MYVAR2})
exten => 1000,5,Eval(RETURNVAR=${MYVAR1}${MYVAR2})
exten => 1000,6,NoOp(RETURNVAR = ${RETURNVAR})
exten => 1000,7,NoOp(RETURNVAR = ${${RETURNVAR}})

   -- Executing SetVar("IAX2/production@production/1", "Line1=200") in new stack
   -- Executing SetVar("IAX2/production@production/1", "MYVAR1=Line") in new stack
   -- Executing SetVar("IAX2/production@production/1", "MYVAR2=1") in new stack
   -- Executing NoOp("IAX2/production@production/1", "MYVAR1 = Line and MYVAR2= 1") in new stack
   -- Executing Eval("IAX2/production@production/1", "RETURNVAR=Line1") in new stack
   -- Executing NoOp("IAX2/production@production/1", "RETURNVAR = Line1") in new stack
   -- Executing NoOp("IAX2/production@production/1", "RETURNVAR = 200") in new stack

By: Tilghman Lesher (tilghman) 2004-10-02 13:00:26

You can already do this without an application, i.e.
${${MYVAR1}${MYVAR2}}