Lua #EmbeddedProgramming #ProgrammingLanguages
Hey there, fellow coders! 🤓 Have you ever found yourself scratching your head over Lua and its popularity in embedded programming? 🤔 Well, you’re not alone! Let’s dive into this topic together and shed some light on why Lua is a great choice for embedded systems.
Here are some reasons why Lua shines in the world of embedded programming:
- Lightweight: Lua is known for its minimalistic design, making it a perfect fit for resource-constrained environments like embedded systems.
- Flexible: Lua offers a high level of flexibility, allowing developers to easily modify and extend the language to suit their specific needs.
- Easy Integration: Lua can be seamlessly integrated with C code, making it a great choice for systems that require a mix of high-level and low-level programming.
Now, to address the question of why Lua is preferred over C in embedded programming, here’s a possible solution:
- Lua for Prototyping: Consider using Lua for rapid prototyping and testing in embedded systems. Its simplicity and ease of use can save valuable time during the development process.
So, what are your thoughts on Lua in embedded programming? Share your insights and let’s keep the discussion going! 💬 #CodingCommunity #LuaProgramming #EmbeddedSystems
Lua is fast and tiny compared to languages like Python and JS, and it’s significantly easier than C. This makes it a great choice for embedding into other programs/systems.
When they roast the pig out on the spit and the girls are dancing the hula you will know why Lua is great.
because people find lua easier than C and they rather have slower code than learn another language
It’s a super simple language. You can learn the basics (which is enough for configuring nvim) in < 30 minutes.
Do you mean “embedded” as in “embedding a scripting language in (for example) C++”, or as in “embedded systems (microcontrollers and the like)”? Very different answers depending on that.
Edit: Why is this even getting downvoted, I’m just asking for additional context…
C has to be compiled, it’s also low level so very difficult.
The obvious answer is that it is tiny in size and extremely easy to learn. Lua is the easiest programming language in world, if you don’t count learning tools like Scratch. If you already know another language, Lua takes 15 minutes to learn. You cannot say the same for C.
What’s not so obvious is that it is designed to also be extremely easy for an C/C++ engine/framework developer to integrate. On top of making coding easier, it is also a simple way of limiting functionality from people using the engine.
What about the Lua language itself that makes it easy? It is designed to be simple, and to achieve that, it makes controversial changes to programming conventions. Variables are global by default, indexes start at 1, and it uses a single data structure known as the table that just works for most use cases.
For power users, there is also a feature known as “metatable” that allows you to add new features to the language as needed, such as proper object-oriented programming.
Lua is excellent for what it tries to do, but by-design, it’s slightly non-conventional, and it can be off-putting for some people.
Fast and easy to learn. Plus it was specifically created for the purpose.
You ussually can use C instead. Or rust. Or go. Or any other language that compiles to wasm (thinking embedded here).
Lua is an easy to learn one for people who don’t know C, rust, etc. Much lower learning curve.
Theres no such thing as an array or map. Its a table. Maybe an array-like table, but its still a table. And tables can have key-value values or index values (technically k:v is also an index value but w/e)
The point is that you have something that can be reinterpreted and reloaded on the fly. C, in most of its forms, needs compilation.
Embedded programming is usually understood as the programming of computers embedded into devices, like microwaves and doorbells – Lua is “embedded” as a scripting language in other programs, often games, but that is usually called **scripting**.
A scripting language doesn’t need to be fast or efficient or able to handle large and complex programs. Usually a script can be a few lines of code, mostly just code that manipulates existing objects. For instance you could write a script that finds all enemy-objects within range, and disables their movement, when the player picks up or uses a certain item.
Maybe write something like:
for enemy in locality.enemies do
enemy.freeze()
end
or similar.
The idea is that a scripting language has access to every object and method in the “system” (i.e. the game) but it can only “ask” the game-engine to change some pre-defined behaviour, it cannot for instance suddenly add completely new mechanics, physics or cool visual effects that the programmers didn’t anticipate. But it can be modified and re-run while the game is running – nothing has to be compiled or built, and if the script fails, it just stops, and you can try something else, the computer doesn’t crash, the game doesn’t crash.
In a language like C, however, you have to write everything yourself – you dont’ have acces to existing objects, unless your program is compiled with them, and if you were to write code that failed, the entire program, maybe the entire computer, would crash with your program. There simply is no benefit to using C for scripting … Even if it were possible.
*If you were actually asking about real embedded programming (for the hardware), I wouldn’t understand why anyone would or could use Lua either.*
I think you’ve misunderstood, Lua isn’t designed to be used in _embedded programming_, it’s designed to be embedded inside other C, C++ programs. This isn’t _embedded programming_.
lua is good for modding things, especially video games.