Combining python and lua

Status
Not open for further replies.

ewdpb

Member
Oct 3, 2019
151
19
18
Hi all,

I am trying to write a basic IVR. What it does is:

1. Fetch some data from database at call start
2. Interact with the caller
3. Fetch some data from remote Web Services
4. Interact with the caller again.

I have been trying to implement 1 and 3 with lua and while it does work, some things are just, from my point of view, awfully convoluted. I was thinking of combining python and lua like this (just an example)

1575467773843.png

I think it should work. But I would like to have your views on that approach.

I know everything can be done with either lua or python. My problem with lua is that I highly dislike the language and the lack of libraries to do the simplest things is irritating. I prefer python but I keep reading that it is not as performant as lua when doing telephony functions (speak, say, collect digits, etc.) there is also something about synchronous vs asyncronous that I am still trying to figure out what it means.

So, what do you guys think? Any constructive opinion is welcome.

Thank you.
 

Attachments

  • 1575467144956.png
    1575467144956.png
    23.4 KB · Views: 12
Last edited:

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,498
413
83
You pose an interesting question, and I hope others will chip in with their views.

My first encounter with Lua was when I started to play with FreeSwitch. I had not heard of it before then. As a C programmer, my preferred scripting languages were Perl and PHP. I never got on with Java/ Javascript despite it's similarities to C++.

The Freeswitch Wiki has quite an old page entitled Script Language choice:
https://freeswitch.org/confluence/display/FREESWITCH/Script+Language+Choice
It recommends the use of Lua and to some extent Perl, but says that Python and Javascript are not a good choice for embedded telephony programming.

Lua is fast to initiate and many of the Lua libraries are actually implemented in C, which will help keep processing speed high. This is important if you want to develop a solution that will scale up to handle many calls per second.

You mention a lack of Lua libraries irritating but there are quite a lot out there:
http://lua-users.org/wiki/LibrariesAndBindings

For my telephony scripting, with FreeSwitch, I'm going to persevere with my learning curve in to Lua. - It's not that bad!

Having said that Sippy Inc. have written a complete SIP back to back user agent entirely in Python.
https://github.com/sippy/b2bua

To answer your last question about synchronous vs asyncronous. I think in the context you mean, it refers to if the calling process waits for the script to complete, or if it just fires off the script and carries on.
 
Last edited:
  • Like
Reactions: ewdpb

ewdpb

Member
Oct 3, 2019
151
19
18
Thanks @Adrian Fretwell , this is the kind of feedback I was looking for. I also found the suggestion to use LUA and I have been doing my best to get to terms with it. What I found annoying is dealing with simple things (e.g. how many rows a SQL query returns? (that should be straigtforward)) But any way, that is not the point. Your view on the use of scripting language was what I was looking for. I also had no idea LUA existed before starting with freeswitch!

Let's see if some other people contribute with their views on this.

Thanks very much!
 
  • Like
Reactions: Adrian Fretwell

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,498
413
83
Hi @Adrian Fretwell , I forgot to ask: are python scripts syncronous or syncronous then? Do you happen to know?

Thanks!
Nothing to do with the scripting language. Just depends on how the script is called, whether the calling process waits for the script to complete or not. Most of the time scripts are executed asynchronously so the calling process will wait to see the result (output) from the script.
 
  • Like
Reactions: ewdpb

ewdpb

Member
Oct 3, 2019
151
19
18
OK, thank you. So, in the case of freeswich I understand one can call a script using mod_[something] : mod_lua, mod_python, mod_erlang, etc. or using ESL. Is that what you are refering to? I realize the answer to it may be too simple but I have not really been able to understand exactly how it all exactly works. Documentation is too open in the way of "you choose what you believe is better for your app", which is a good enough explanation when you are an expert on the thing already but when you are trying to learn.... well, not so much.

Thanks!
 
Status
Not open for further replies.