[asterisk-dev] Execution environment of Lua dialplan and persistent state?

Matthew Nicholson mnicholson at digium.com
Thu Apr 7 13:27:13 CDT 2011


On Wed, 2011-04-06 at 13:29 -0700, dlakelan wrote:
> I am writing a small dialplan in lua and want to have some persistent 
> state. For example I want someone to be able to dial *DNR (*367) to set 
> a "do not ring timeout". The idea is that asterisk will goto a context 
> where the "s" extension simply prompts for the number of minutes they 
> want to not have the phone ring and then an extension "*XXX" reads the 
> extension dialed and sets the time until which the calling line should 
> go directly to voicemail. It seemed straightforward to put into a lua 
> table the timeout value.
> 
> What I've found is that it seems that every time a call is routed global 
> variables seem to be reset to their original values so the timeout is 
> erased. so I've taken to putting this persistent state into a mysql table.

You could also accomplish this using asterisk's internal DB.  Perhaps
something like this:

channel.DB("DNR/extension_goes_here"):set("on")

Read it like this:

channel.DB("DNR/extensions_goes_here"):get()

Or if persistence between asterisk restarts is not important, you could
use global channel variables.

channel.GLOBAL("varname"):set(value)



> It got me wondering what the situation is with lua dialplans? Every time 
> a call is routed are all the commands in the extensions.lua executed in 
> a clean environment?

Yes, each channel gets it's own lua environment to run in.

-- 
Matthew Nicholson
Digium, Inc. | Software Developer




More information about the asterisk-dev mailing list