Alternatives to Lua as an embedded language?

后端 未结 7 475
盖世英雄少女心
盖世英雄少女心 2021-01-30 05:23

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 scr

相关标签:
7条回答
  • 2021-01-30 05:34

    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.

    0 讨论(0)
  • 2021-01-30 05:35

    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.

    0 讨论(0)
  • 2021-01-30 05:38

    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.

    0 讨论(0)
  • 2021-01-30 05:40

    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.

    0 讨论(0)
  • 2021-01-30 05:47

    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.

    0 讨论(0)
  • 2021-01-30 05:51

    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.

    0 讨论(0)
提交回复
热议问题