Using Lua for core application logic, gluing to C++ GUI

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Lua for core application logic, gluing to C++ GUI

Ivan Krylov
Hi!

I'm planning to write a networked application. I'm not a professional
programmer and I don't have a lot of free time, so I'm trying to
save as much time as possible by preventing duplication and choosing
the best fitting technology for the task at hand. Unfortunately, I
would like the application to have GUI and run on a wide range of
targets (major PC OSes + Android), so some C++ programming is
inevitable (since C++ is the "lowest common denominator", code
depending on reasonably portable libraries can be expected to compile
without changes), especially the UI part (where I would have to
implement two different user interfaces).

I'm considering Lua for the cross-platform part of the code. On the one
hand, it might lower the attack surface (much harder to have an
arbitrary code execution vulnerability without eval or raw pointers);
also, I'm being told that Lua coroutines are great for expressing
algorithms that do lots of network I/O. On the other hand, I would have
to write my own wrappers for all outside dependencies I may want to
bring into the project (more potential vulnerabilities here?); and if I
wanted to publish my algorithm as a library usable from other languages,
I would also have to wrap Lua back into a set of C routines (for C is
the lingua franca of programming languages).

Speaking of outside dependencies, I absolutely need TLS sockets and
hashing and may try to use DTLS, sound I/O and codecs in the future.

Is it a good idea to write the core/library part of a networked
application in Lua, then wrap it in C++ launcher/interface (built using
Qt or JUCE for most cross-platform compatibility)?

--
Best regards,
Ivan

Reply | Threaded
Open this post in threaded view
|

Re: Using Lua for core application logic, gluing to C++ GUI

Sean Conner
It was thus said that the Great Ivan Krylov once stated:
>
> Speaking of outside dependencies, I absolutely need TLS sockets and
> hashing and may try to use DTLS, sound I/O and codecs in the future.

  I just finished up a TLS wrapper for Lua [1] and I have used it with Lua
coroutines [2] to handle event-driven servers [3].

> Is it a good idea to write the core/library part of a networked
> application in Lua, then wrap it in C++ launcher/interface (built using
> Qt or JUCE for most cross-platform compatibility)?

  I guess.  I tend to write the main application in Lua and use C for
wrapping up libraries or for speed (in my case, mostly wrapping up
libraries).  I also create an executable that embeds Lua plus all the
modules required for the program to run included.  I have no opinion on the
GUI part as I don't write those types of programs.

  -spc

[1] https://github.com/spc476/lua-conmanorg/blob/master/src/tls.c
        but not yet available via LuaRocks.  Soon though ...

[2] Again, I need to publish this code ... sigh.

[3] I do a similar thing at work---use Lua with extensive coroutine
        support to handle SIP processing.  

Reply | Threaded
Open this post in threaded view
|

Re: Using Lua for core application logic, gluing to C++ GUI

Ivan Krylov
In reply to this post by Ivan Krylov
Hi Milind,

On Tue, 28 Aug 2018 16:28:13 -0700
Milind Gupta <[hidden email]> wrote:

> For me I did not need to support Android so I chose to write my code
> using Lua with IUP ( http://webserver2.tecgraf.puc-rio.br/iup/) for
> doing the GUI, this is also from the same place that created Lua.

Perhaps it's a good idea for me to use IUP, too, since none of the
intended users actually run macOS and IUP is very good at preserving
native look and feel on Windows and *nix-like operating systems.

> Used LuaSocket and LuaSec for network programming and sometimes
> lua-curl.

LuaSec is very simple to use but is only able to verify connections with
certificates loaded from files, unless I overlooked a method. Luaossl
is much more verbose and may not be supported on Windows.

But there is no such thing as "free lunch", I guess.

> For your case I would have probably gone with Corona SDK (
> https://coronalabs.com/). You can make the whole application there
> and also the GUI and it will be available on iPhone and Android as
> well.

Thank you for the suggestion! Being able to build the whole Android app
in Lua is great.

--
Best regards,
Ivan

Reply | Threaded
Open this post in threaded view
|

Re: Using Lua for core application logic, gluing to C++ GUI

Daurnimator
On Thu, 30 Aug. 2018, 21:16 Ivan Krylov, <[hidden email]> wrote:
Luaossl
is much more verbose and may not be supported on Windows.

Luaossl supports windows for a little while now, I contributed the PR for it!
Reply | Threaded
Open this post in threaded view
|

Re: Using Lua for core application logic, gluing to C++ GUI

Ivan Krylov
In reply to this post by Ivan Krylov
>   I just finished up a TLS wrapper for Lua [1] and I have used it
> with Lua coroutines [2] to handle event-driven servers [3].

This is great, thank you! I was wondering what to use for TLS (mbedTLS
looks interesting if the target language is plain C), but libtls API
feels more straightforward. I will still probably have to experience
the wonders of cross-compiling for Android.

> I tend to write the main application in Lua and use C for
> wrapping up libraries or for speed (in my case, mostly wrapping up
> libraries).

Thanks for confirming that this approach is viable.

> I also create an executable that embeds Lua plus all the
> modules required for the program to run included.

I wonder if it is considered a sane thing to wrap a library implemented
in Lua as C/C++ code.

--
Best regards,
Ivan

Reply | Threaded
Open this post in threaded view
|

Re: Using Lua for core application logic, gluing to C++ GUI

Ivan Krylov
In reply to this post by Ivan Krylov
> On Thu, 30 Aug. 2018, 21:16 Ivan Krylov, <[hidden email]>
> wrote:
>> Luaossl is much more verbose and may not be supported on Windows.
> Luaossl supports windows for a little while now, I contributed the PR
> for it!

Thank you! More choice is good news.

I remember seeing a phrase like "Windows support is not tested but
should be easy, pull requests welcome" with regard to luaossl. I cannot
find it now, so I guess I was confused when I wrote my message.

--
Best regards,
Ivan