Live data from Hacker News

Lua beats MicroPython for embedded devs

embedded.com

31–40 of 87 posts

Re: Lua beats MicroPython for embedded devs

#31
post #16

Earlier quoted context omitted.

I have been developing Lua-heavy embedded products as a freelancer for about 20 years now, including VoIP devices, home automation controllers, industrial routers, digital video recorders, and more. These systems typically consist of a Linux kernel, some libc implementation, the lua interpreter and a few 3d party libs support libs to help building the app. The Lua apps ranges from 30k to 100k lines of code, depending…

I am currently working on an embedded system with 264Kb of RAM and 4Mb of flash. Do you think Lua could be used in such limited settings? I am also considering the berry scripting language [0]. [0] https://berry-lang.github.io/

I haven't worked on a system that limited (not even OpenWRT routers) since a dev board in college.

The experience I had there might be your best bet for something productive. That board came with a 'limited C-like compiler' (took a mostly complete subset of C syntax and transcribed it to ASM).

You'll probably be doing a lot of things like executing in place from ROM, and strictly managing stack and scratch pad use.

The 64MB of RAM and 8MB (I assume that's 64Mbit) of ROM allow for highly liberating things like compressed executable code copied to faster RAM, modify in place code, and enough spare RAM otherwise to use scripting languages and large buffers for work as desired.

Re: Lua beats MicroPython for embedded devs

#32

Earlier quoted context omitted.

Lua can be quite an elegant language once you get to know it well, but you can still use it like most other programming languages, it's not that weird. There are quirks like arrays starting at 1 (and all arrays being hash tables) but they don't take that long to get used to. The real strength is in the ecosystem and implementation itself, it's designed to be easily embedded into applications and there's not really mu…

> There are quirks like arrays starting at 1 I know it’s probably and overreaction, but this was a compete non-starter for me.

Not having to put length-1 everywhere is a good thing, actually.

Re: Lua beats MicroPython for embedded devs

#33
post #4

What’s the dev experience actually like for serious Lua? I’ve only used it for some basic neovim configuration. The dynamicism and lack of type hinting in Python that was the norm when I started having to review professional code, after transitioning from pure mathematics, was a major cognitive blocker for me. With a math paper I could typically skim the first few pages to map the author’s particular symbology (if no…

> What’s the dev experience actually like for serious Lua The dev experience for lua is f-ing awful. The language is small, but not “simple”; it’s stuck in 1985. The tooling is nearly non-existent and the stuff that does exist is a joke. The few libraries that exist are awful and barely maintained; the maintained libraries are maintained by neckbeards with a god-complex. The community is “reimplementing everything by…

nginx and Roblox and redis and nmap and neovim and cryengine … the list goes on

There are a LOT of tools with embedded Lua scripting capabilities.

Re: Lua beats MicroPython for embedded devs

#34
post #16

Earlier quoted context omitted.

I have been developing Lua-heavy embedded products as a freelancer for about 20 years now, including VoIP devices, home automation controllers, industrial routers, digital video recorders, and more. These systems typically consist of a Linux kernel, some libc implementation, the lua interpreter and a few 3d party libs support libs to help building the app. The Lua apps ranges from 30k to 100k lines of code, depending…

I am currently working on an embedded system with 264Kb of RAM and 4Mb of flash. Do you think Lua could be used in such limited settings? I am also considering the berry scripting language [0]. [0] https://berry-lang.github.io/

That sounds like something the size of an ESP32.

Assuming your flash allows XIP (execute in place) so all that memory is available for your lua interpreter data, you should at least be able to run some code, but don't expect to run any heavy full applications on that. I don't know Berry but it sounds like a better fit for the scale of your device.

But sure, why not give it a try: Lua is usually easy to port to whatever platform, so just spin it up and see how it works for you!

Re: Lua beats MicroPython for embedded devs

#35
post #31

Earlier quoted context omitted.

I am currently working on an embedded system with 264Kb of RAM and 4Mb of flash. Do you think Lua could be used in such limited settings? I am also considering the berry scripting language [0]. [0] https://berry-lang.github.io/

I haven't worked on a system that limited (not even OpenWRT routers) since a dev board in college. The experience I had there might be your best bet for something productive. That board came with a 'limited C-like compiler' (took a mostly complete subset of C syntax and transcribed it to ASM). You'll probably be doing a lot of things like executing in place from ROM, and strictly managing stack and scratch pad use. T…

[deleted]

Re: Lua beats MicroPython for embedded devs

#36
post #5

When I decided to create a game engine where the game could be entirely scripted in a scripting language, I was choosing between JavaScript (QuickJS), Python (Boost.Python), and Lua (Sol2). The ease of embedding Lua, even with a C++ wrapper, is incredible. With little effort, I now have something I consider “ready”. Not to mention, it’s a very lightweight VM. https://github.com/willtobyte/carimbo

Boost.python is not the best scripting tool to be honest. So, that might affect your judgement as well.

I've yet to find an even decent python binding generator, TBH.

Generally, I use pybindgen to get the basic module and then hack on that by hand. The main problem is most C(++) libraries aren't designed to interoperate with managed memory languages so most of the work is figuring that out. Don't get me wrong, I've tried to work within the binding library (with pybindgen at least) but the amount of work for anything even slightly complicated isn't really worth it.

For a project with a major python API (like blender) you're better off crafting your own python class generator (again, like blended does, and even that has some major issues around object lifetime management). Best would be to design the underlying library/application with python integration in mind but that's not always possible if you want to include other libraries.

I can say I did mess around with using lua as an embedded scripting language within an application years ago and it wasn't too difficult from what I remember. It was only ever a proof-of-concept and didn't go too far so I never ran into the inevitable edge case as one always does with these sorts of things.

Re: Lua beats MicroPython for embedded devs

#38

Earlier quoted context omitted.

Boost.python is not the best scripting tool to be honest. So, that might affect your judgement as well.

I've yet to find an even decent python binding generator, TBH. Generally, I use pybindgen to get the basic module and then hack on that by hand. The main problem is most C(++) libraries aren't designed to interoperate with managed memory languages so most of the work is figuring that out. Don't get me wrong, I've tried to work within the binding library (with pybindgen at least) but the amount of work for anything ev…

That's very true actually. Boost.Python is not good, but the alternative then is actually doing everything ourselves which seems worse in short term.

Re: Lua beats MicroPython for embedded devs

#39
As a hobbyist I just use Arduino (via platformio). I don't think I need an interpreter of any sort for microcontrollers because recompiling and uploading the flash on hobbyist boards is quick and easy.

But I'd like to try some other compiled language someday because I'm not a big fan of C++. Any recommendations for something that works well with a Raspberry Pi Pico?

Post reply on HN