Anyone know the history of picking lua for an embedded interpreter?

Hey folks!

I was curious if anyone know the history of or technical reasoning to picking lua for an embedded scripting language interpreter.

I've noticed pandoc also embeds lua.

No language aesthetics from me. Just curious :grinning_face_with_smiling_eyes:

1 Like

I'm not an OpenWRT developer but I'm pretty sure that there wasn't any other alternative.
Any other scripting language are so much bigger that even can't fit into 4mb flash. Maybe only perl can fit into but it's a terrible language.
In the same time Lua was actively used by game developers and is small and well tested, and even has a JIT compiler. But most important that it's easy to embed and execute from a C program. Basically uhttpd web server has a built-in Lua interpreter and that's why it can execute Lua scripts so fast.

Scripts are needed for several reasons:

  1. To avoid cross compilation for all platforms
  2. To make development easier: no need to manually free memory, high level statements.
  3. For a better security: many Luci plugins and templates have a lower code standard and may have vulnerabilities. So it's important to execute them in some kind of sandbox.
  4. To use less space: high level constructs like param == ""' takes only few bytes while compiled from C this will use much more space.

And even now there is no any other good alternatives. I know only this that are used for microcontrollers like STM32:

Anyway any of those micro version of languages doesn't make a lot of sense. Lua anyway can be learned in a day, so why bother? It may be a good to use Python to be able to use it's libraries but... then you'll need the whole Python batteries that can't fit into old devices.

But I think that new routers now have a lot of space and faster CPU. And from what I see almost all they have the CPython installed. In the same time Rust, Go and even Kotlin Native one day will be fully supported by OpenWRT and most developers will use them.

In the same time for a basic scripting it may be a good idea to just extend BusyBox ash to become a full language i.e. add arrays and maps and that really may be good option


Thank you for the helpful summary and explanations @stokito!

Ah, that makes total sense to me! I hadn't realized that core limitation.

Sounds like a good fit for an openwrt project.

This sounds fun!
I program in Rust and feel like its design values line up with some of the needs OpenWrt devices have. I have also heard the C FFI is quite ergonomic. But mainly I'm curious about writing or contributing something in Rust :grinning_face_with_smiling_eyes:

1 Like


The ucode language is a tiny general purpose scripting language featuring a syntax closely resembling ECMAScript.