Embedding Lua 5.1 in Asterisk 18.104.22.168
I’m sure I had something in mind when I started this and no doubt it’ll come to me once I fill out some callbacks so I can do more from the lua side than call “ast_log”. I still need to figure out a reasonable way to allow the lua side of things access to all the channels using the lua application. To do that, I need to read up on how Lua handles threads. What I have now is more proof I can set up an environment to do this than something that is useful. I wrote an Asterisk application that exposes a Lua 5.1 interperter and sketched out the Makefile voodoo and a nearly empty .i file to expose Asterisk functions to the lua side with SWIG.
So in extensions.conf, I have: exten => 8302,1,Answer exten => 8302,n,Lua(awesome.lua) exten => 8302,n,Hangup()
and in etc/asterisk/awesome.lua: function app_exec() log_info(“awesome!\n”) end
It doesn’t pass in anything to allow the lua side to act on the channel, but that’s next. I’m pleased at how nicely documented (so far) both the Asterisk and Lua sides of this dance are. I used a few tutorials about embedding Lua (plus the manual) and plus the very helpful tutorial writing native extensions for Asterisk 1.2.
I’m sure I’ll release it (under the GPL, since Asterisk is GPL) if it gets much further. As an example of how easy embedding Lua is, if nothing else. People that know me might have expected me to have done this with Python instead, but somebody else already did — though pyasterisk does not appear to be maintained. Of course, unless I end up using this Lua embedding for something I’m sure it’ll suffer the same fate.