[asterisk-dev] LUA in Asterisk. was [svn-commits] tilghman: trunk r88250 - in /trunk: ./ build_tools/ configs/ include/asterisk...

Matthew Nicholson mnicholson at digium.com
Mon Nov 5 11:55:01 CST 2007

On Sat, 2007-11-03 at 21:20 -0500, critch wrote:
> On Sun, 2007-11-04 at 00:30 +0200, Tzafrir Cohen wrote:
> > I looked at the added code and wondered how exactly it's supposed to
> > work. Or more specifically: when is code evaluated.
> > 
> > Does Asterisk include a lua interpreter?
> > 
> > It seems that lua needs to be used at dialplan loading time using #exec .
> > Are there any plans of making the lua support include the "compiler" as
> > well (like the current AEL code does)?
> > 
> > Can anybody spare a few words on why lua was used? I'm generally not
> > well-familiar with it so I wonder where it may be much more useful that
> > conventional Asterisk dialplan (and AEL) and also what are its
> > limitations and its overhead.

> [...]

> My only real concern is this, how will errors be handled? if you write a
> dialplan in a interpreted language and have say a syntax error, should
> asterisk die?

No, asterisk should not die and will not in this case.  If there is a
syntax error, this will be detected when the module is loaded or
reloaded.  On load, this will cause the module to print an error and not
load, no reload, this will cause the most recent successfully loaded
extensions.lua to continue to be used and an error will be displayed.

For runtime errors, the error will be printed, and the 'e' extension
will be executed, if it exists (if it does not exist the channel will
hangup).  This is similar to the current behavior if an application
encounters a "fatal error".

> Also with more and more complex dialplan logic being built
> in, this smells a lot like the mod_perl and similar for apache.
> Basically a long running app that runs in the same process space.

This is not the case at all.  The lua code runs in the same thread as
what ever called it (in most cases this will be the pbx thread for the
channel).  Just like applications that are run from the dialplan.  No
new threads or processes are created.

> I believe we need to look into how these apps controlling the dialplan
> are going to behave in a multithreaded environment.

Each lua instance runs in the pbx thread and has no access to other
threads.  Lua supports coroutines, which are not real threads and all
run in the same thread that lua is running in.

> Most programmers who use scripting languages are used to only dealing
> with a single thread and not worrying so much about garbage
> collection.  

Lua is fully garbage collected.  There should be no resource leaks.
Matthew Nicholson

More information about the asterisk-dev mailing list