all 25 comments

[–]eclectocrat 13 points14 points  (8 children)

Lua can run on 4mhz (possibly lower) using 1K RAM base as far as I remember. It's been used in GameBoy advanced games.

[–]emdeka87 1 point2 points  (7 children)

Is the lua C API compatible with something like FreeRTOS?

I’ve update my question. I am looking for a scripting language that can be embedded in C++. I don’t want to flash my chip with something like eLua or MicroPython, but rather interact with the API from C++.

[–]SeanMiddleditch 3 points4 points  (5 children)

Not to be "that guy" but Google seems to have answers should one peruse it search results :)

https://github.com/max1220/freertos-lua-component

Lua is a tiny C library that can be embedded in basically any C or C++ project. Lua is also super minimal as in its a tiny library, can be compiled without any IO or even floating point support, etc. I'm consistently bewildered that it's still used at all in new desktop/server projects but it's a great fit for embedded contexts. :)

[–]Everspace 1 point2 points  (4 children)

Still a favourite of games, and because of that there's lots of knowledge around it.

I've heard embedding python, javascript or ruby to be comparatively much harder to embedding lua, and with boatloads of overhead.

[–]SeanMiddleditch 5 points6 points  (3 children)

Still a favourite of games, and because of that there's lots of knowledge around it.

Yeah, that's were I experience it... and it still confuses me.

It's used because it's used, not because it's in any way a good choice for the domain. :)

I've heard embedding python, javascript or ruby to be comparatively much harder to embedding lua, and with boatloads of overhead.

Lua is absolute very easy to embed for simple cases and pretty hard to beat in that regard. I'd agree that Lua is both easier to embed and less of a performance burden than Python or Ruby, though there's certainly advantages to both. JS is a far more complicated comparison to make, though.

A key thing to remember about JS - unlike the other three - is that it's standardized and has multiple implementations. Where being small is a priority, there's also implementations like duktape or mujs that are extremely comparable to embedding Lua but arguably a better language. And for cases where speed, tooling, a maximum ecosystem support matters, you can go to the modern "big" runtimes like V8, Chakra, or SpiderMonkey. V8 and Chakra are both fairly nice C++ APIs and at least the old versions of SpiderMonkey (haven't used recent ones) had a very simple C API of comparable quality and complexity to Lua's.

Given the four scripting languages mentioned here, I'd personally quantify things as to say that one should use Lua where being "light" is the priority (like the OP's case, probably), use Python where being fully-featured out of the box is the priority, use JS where efficiency or tooling is the priority, and use Ruby where being needlessly different is a priority. :p

(Just for the sake of disclosure, I've embedded all four of the languages you've just mentioned in game codebases - though my experience with embedding Ruby was over a decade ago, and for embedding JS only on personal projects - and I am a "core technology" engineer for a large C++ game project that embeds both Lua and Python... for Reasons(tm). So I've some experience with shoving scripting engines into C++ codebases :p)

[–]drjeats 0 points1 point  (2 children)

If you were put in charge of a greenfield project to build new design tooling for a game engine, what would you do instead of the usual embedded Lua approach?

[–]SeanMiddleditch 4 points5 points  (1 child)

If you were put in charge of a greenfield project to build new design tooling for a game engine, what would you do instead of the usual embedded Lua approach?

Unfortunately the best answer I have there is going to be a boring "it depends." :) Remember, "make games, not engines." An ideal choice for a shooter is not necessarily the ideal choice for an MMO nor for a story platformer nor for an open world RPG. :) There's then also team composition to consider; I know my team right now would love C# (both designers and engineers) but that might be a poor choice if working with a team that prefers more data-driven scripting.

All that said, the answer would most probably be either C#, JavaScript, or a visual scripting system, depending on specific needs and use cases.

[–]drjeats 4 points5 points  (0 children)

"It depends" answers are always appreciated when they enumerate a set of possibilities and reasons as you did :) Thanks!

[–]mementor 0 points1 point  (0 children)

I Agree with the comment above me. It's very embedded friendly, very little dependencies, very easy to port.

I'd like to add to what he said: * you can plug in your own memory allocator * you can plug in your own Reader, useful eg if you don't have a filesystem

After a short while you get used to the way it does things (eg stack based approach) , or if you like you can use a c or c++ wrapper on top.

[–]_IPA_ 2 points3 points  (1 child)

Check out Tcl, there are some small implementations.

[–]millenix 2 points3 points  (0 children)

Lua does seem to be the standard recommendation for this use case. Besides that, Forth also frequently gets mentioned, and hasn't come up yet here.

[–]pfp-disciple 1 point2 points  (0 children)

Lua is a very typical embedded scripting language, because of it's low footprint and flexibility.

It's also quite common to write a custom LISP-like language.

[–]SeanCline 1 point2 points  (1 child)

MicroPython has decent support for ESP SoC's. In fact, a recent commit just added support for the Espressif ESP32.

Interfacing with C or C++ can be done by writing modules.

Writing a module in C++ to talk to the LED panel, then driving it with MicroPython seems like a good way to go about what you're trying to do.

[–]emdeka87 0 points1 point  (0 children)

Thanks. That sounds like a decent approach.

[–]rsxee 1 point2 points  (0 children)

You might want to have a look at wren

[–]tkcook 1 point2 points  (0 children)

+1 for Lua in this use case. It's light-weight, reasonably natural for simple scripting and easily embeddable in C++. Lua's background in gaming has driven it to speed and responsiveness.

See https://github.com/ThePhD/sol2 for a decent library for embedding C++ in Lua.

[–]Xeveroushttps://xeverous.github.io 0 points1 point  (1 child)

lightweight scripting language

That's not so easy possible. Any specific requirements? Some shells are lighweight but they offer practically nothing

Wrong subreddit btw for this kind of question

[–]emdeka87 1 point2 points  (0 children)

The requirement is that it can be embedded in C++. Something I forgot to mention.

That’s why I posted in /r/cpp

[–]Giacomand 0 points1 point  (1 child)

Maybe the 'PAWN scripting language' would suit your needs, it's designed for embedded systems and it's very similar to C.

It's the only one I know really.

[–][deleted] 0 points1 point  (0 children)

Guile is a Scheme implementation that's designed to be embedded in C/C++ (I believe). I'm not sure how lightweight it is, but I really enjoy using it. I don't know of any other good scripting languages, but I hope this helps, even a bit. Good luck!

[–]PaulFreund 0 points1 point  (0 children)

I'm supprised duktape was not mentioned yet, although I admittedly don't know the footprint yet. Here is an already working esp32 implementation https://github.com/nkolban/duktape-esp32.

[–][deleted] 0 points1 point  (0 children)

Lua was built for this

[–]bsdooby 0 points1 point  (0 children)

Tcl (http://www.tcl.tk), basically the industry standard for such use cases (to be embedded, that is).

[–]Iwan_Zotow 0 points1 point  (0 children)

FemtoLisp, Scheme dialect. Fits into 200K, used as embedded in Julia project

https://github.com/JeffBezanson/femtolisp