Alternatives to Lua as an embedded language?

30,781

Solution 1

Since you say "embedded system" and "small and fast" and "integrate nicely" I would say you are correct that Lua is the number one if not the only choice. But I no longer agree that the programming language has "quirky corners". Firstly, the book Programming in Lua is simply splendid, one of the best books I have ever read. Secondly, some of the "quirky corners" come from the fact that the language is very orthogonal and clean, which in the long run is an asset, not a drawback. I find for example JavaScript much worse. If you read "Javascript the good parts" the author explains in length why some constructs in the language are design mistakes and why one should avoid the new operator. Not so in Lua, the bad parts have been removed, for example the quirky upvalue stuff was replaced with standard syntactic scoping in version 5.x.

My view is actually that Lua is a language with far less quirky corners than most other languages! We use it in a commercial project and we are more than happy with it.

Solution 2

I wholeheartedly recommend Lua for your use case. However, Forth is an alternative--especially for resource constrained embedded devices--that has not yet been mentioned.

Solution 3

There's always Lisp. :) But that underscores the fact that Lua is in fact less "quirky" than most languages. It was designed for non-programmers and reads like pseudocode. It has clean, uniform semantics (first class nested functions with lexical scoping; multiple assignment; multiple return values; a single, flexible data structuring mechanism with clean constructor syntax; etc.) which make it very easy to learn, read, write, etc. It also happens to be unexpectedly powerful and expressive (proper tail calls, continuations, metaprogramming, etc.)

The only really "quirky" aspect of Lua is that arrays index from 1, and that fact that it doesn't borrow C's conventions like everybody else (~= rather than !=, -- rather than //, etc.), but these are mostly quirky through the eyes of programmers habituated to C-like languages.

An alternative might be Squirrel, which is inspired by Lua, has similar goals, but C-like syntax. I've not used it though, so I don't know well it meets it's goals.

Solution 4

Tcl was designed from the ground up to be an embedded language, and has been around for decades. Plus, it is a perfect choice for developing a domain-specific language because of its highly extensible nature.

I don't know a lot about the DSP world, but when you google "dsp lua" and "dsp tcl" you get twice as many hits for Tcl.

Solution 5

With your requirements (small footprint, little quirks and integration with C++), the only option I can think about is Common Lisp.

Some people in this other SO question are recommending CFFI for integrating it with C.

But I'd stick with Lua if I where you.

Share:
30,781
bastibe
Author by

bastibe

I am an scientist / engineer with specialization in signal processing and audio technology.

Updated on July 08, 2022

Comments

  • bastibe
    bastibe almost 2 years

    I am working on an embedded system running Linux on a DSP. Now we want to make some parts of it scriptable and we are looking for a nice embeddable scripting language. These scripts should integrate nicely with our existing C++ code base, be small and fast.

    I understand that Lua is the industry choice for problems like this. We will probably go with Lua because it is tried-and-true and proven to be stable and so on. However, as a programming language it has some rather quirky corners.

    So, what alternatives are out there for embeddable languages?

    EDIT:

    This is about a year later.

    We actually used Lua on our embedded system and it performs marvelously well. Over time, we added more and more scripting support to more and more parts of the project and that really helped to bring it along.

    Performance is outstanding, really. Even rather complex operations that involve searching through long arrays or fancy string operations perform surprisingly well. We basically never ran into Lua related performance problems at all.

    Interfacing with C functions is very straightforward and works really well. This allowed us to grow the scripting system painlessly.

    Finally, we were astounded at how flexible Lua proved to be. Our Lua interpreter has to run on a system with a nonstandard memory allocator and without support for the double data type. There are two well-documented places in one header file we had to modify to make Lua work on that system. It is really well suited for embedding!