[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:44:44 CST 2007


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?

Yes and no.  Lua is implemented in liblua and asterisk links against
that.

> It seems that lua needs to be used at dialplan loading time using #exec .

The #exec line is just a convenience thing so that you don't have to
manually add 'switch => Lua' to every context.  The lua stuff is loaded
only when it is used so if you don't have 'switch => Lua' in your
dialplan anywhere then the module will only be used when it is loaded
and reloaded.

The actual extensions.lua file is parsed once when the module is loaded
or reloaded.  At that time the file is read into an in memory buffer,
and loaded from that buffer as necessary.  The first time a channel uses
pbx_lua (performing an extension lookup or executing an extension) a new
lua state is allocated and initialized.  Also each time the pbx core
needs to lookup an extension (before a channel is associated with a sip
call for example) a new lua state is initialized.

> Are there any plans of making the lua support include the "compiler" as
> well (like the current AEL code does)?

There is a lua compiler called luac that comes standard with lua.  You
should be able to precompile your extensions.lua file using it (the
resulting file will need to be named extensions.lua) to increase
perfomance.

> 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.

I implemented pbx_lua first as an experiment to see if I could replace
the pbx core with lua as a scripting language to have a real programming
language available to script call flow in.  From there I molded the code
into a dialplan switch.

I chose lua because it is lightweight, fast, stable, and easy to
integrate into C code.  I have not run any benchmarks with the code yet,
but thinking about how the code works, conventional dialplan and AEL
should be faster doing extension lookups, but lua may be faster actually
executing extensions.  Also lua will probably scale better to larger
dialplans then AEL and extensions.conf will.

The pbx core performs one lookup in the dialplan for each *priority*
that it executes, pbx_lua will perform three (I think) lookups for each
*extension* that it executes.

I could be wrong. :)

-- 
Matthew Nicholson
Digium




More information about the asterisk-dev mailing list