Alternatives to Lua as an embedded language?

ScriptingProgramming LanguagesEmbeddedLua

Scripting Problem Overview


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!

Scripting Solutions


Solution 1 - Scripting

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

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

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

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

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.

Solution 6 - Scripting

Have you considered Python? There's a nice extending and embedding guide available. If you're using Boost, Boost Python is a library for seemless integration between C++ and Python.

Solution 7 - Scripting

>I understand that Lua is the industry choice for problems like this.

A bold claim! I would suggest that if you are already running Linux, the choice is wide open. Linux itself is by no means the "industry choice" for embedded systems; the 'industry' is far more fragmented than that.

A language that is implementable on virtually any system regardless of performance, size, and OS (or even no OS), is Forth. Not the most fashionable language perhaps, but easily implementable and extensible.

Another candidate might be ch, which is an embedable C/C++ interpreter, so you can use the same language for compiled and scripted code.

Solution 8 - Scripting

A more recent alternative is wren:

> Wren is a small, fast, class-based concurrent scripting language > > Wren is a scripting language. Wren is intended for embedding in > applications. It has no dependencies, a small standard library, and an > easy-to-use C API. It compiles cleanly as C99, C++98 or anything > later.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbastibeView Question on Stackoverflow
Solution 1 - ScriptingAndersHView Answer on Stackoverflow
Solution 2 - ScriptingJudge MaygardenView Answer on Stackoverflow
Solution 3 - ScriptingMudView Answer on Stackoverflow
Solution 4 - ScriptingBryan OakleyView Answer on Stackoverflow
Solution 5 - ScriptingkikitoView Answer on Stackoverflow
Solution 6 - ScriptingdariooView Answer on Stackoverflow
Solution 7 - ScriptingCliffordView Answer on Stackoverflow
Solution 8 - ScriptingRealView Answer on Stackoverflow