Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to Lua as an embedded language?

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!

like image 339
bastibe Avatar asked Dec 15 '10 10:12

bastibe


People also ask

What is an alternative to Lua?

The best alternative is Python, which is both free and Open Source. Other great apps like Lua are JavaScript, PHP, C (programming language) and Go (Programming Language). Lua is a powerful, fast, lightweight, embeddable scripting language.

Is Lua used in embedded systems?

Embedded Lua (eLua) is a scripting language designed for embedded systems. It is powerful but small enough to run on microcontroller platforms. Very often while developing complex systems, engineers have to greatly simplify the task of writing final user space applications.

Is Lua obsolete?

While Lua is still used fairly often in gaming and web service, it performed poorly in terms of community engagement and job market prospects. That being said, in spite of its age, Lua's growth has flat-lined rather than declined, which means that although it's not popular, it's not dying either.

Is C++ better than Lua?

The only "real" advantages of Lua over C++ is that you don't have to compile it, and there are a lot of premade Lua interpreters that you can integrate really easily. Sure, you could use C++, but then you've either gotta interpret it, or dynamically link files to your code to use it, and that's just a pain.


2 Answers

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.

like image 183
AndersH Avatar answered Sep 18 '22 17:09

AndersH


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.

like image 25
Judge Maygarden Avatar answered Sep 17 '22 17:09

Judge Maygarden