Comment by fsmv
1 year ago
I built a chatbot with lua plugin commands and I really had an awful experience trying to incorporate it in my C++ program. I really don't understand why people say it's easy to embed because you have to do a ton of stack manipulation to do anything. Not only that but the language itself is cumbersome, frustrating, and does nothing at all to help you when you make a mistake.
I will never use lua again and avoid any project that uses it.
I am in the "Lua sucks" camp. I also found it weird how clunky it is to embed, but my biggest gripe is with the language itself. It just sucks, as its barely a programming language at all. Every Lua project ends up reinventing its own class system or other language feature to get anything done.
I've also never seen a clean (non trivial) Lua codebase before. They're all spaghetti messes and difficult to follow. On the contrary, some of the worst, least maintainable and difficult to read code I've seen has been in Lua.
For configuration (what it was originally designed for) or for very small, non-critical stuff, then it can be a good choice.
With that said, I know some people are very productive with it, and have made impressive things in Lua. It's just not for me.
> It just sucks, as it's barely a programming language at all.
I remember when I thought like this when I was first learning C++ and thought it was awesome because of all the features built into the language. Since then, I've learned that things that are "barely a programming language at all" like Lua—where you can easily learn the whole language and then write, if necessary, reflective object-oriented effortlessly parametrically polymorphic code—are actually the best languages of all. (Such extreme liberalism does require a compensating amount of discipline, as you say.)
Lua has its flaws (implicit nils, the nil/# interaction, default global, 1-based indexing, etc.) but minimalism is one of its major virtues.
Then you get hold of a language that doesn’t have all this mess as a foundation and it feels like you stopped self-suffocating.
you can easily learn the whole language and then write, if necessary, reflective object-oriented effortlessly parametrically polymorphic code
This is all you can do in these languages. Anything above it will share the fragility and ad-hocness of this meaningless language para-olympics.
5 replies →
I enjoyed writing a small module for the Prosody XMPP server, which is written in Lua. Everytime I had to look into the internals I found what I was looking for pretty easily.
[flagged]
My experience has been similar, even though not as drastic. Lua is fine for small extensions and such (e.g. Hammerspoon), but a lack of any kind of a reasonable standard library really bites me the wrong way. Sure, I can write a function to log an array, but why can't I just log an array like a decent human being?
What language did you find was easier to embed, and how does it handle the lifetime management that Lua's embedding API handles with its stack?
The language itself may be a matter of taste. I prefer languages which, "in the face of ambiguity, refuse the temptation to guess," but certainly I've spent enough time using Perl, bash, JS, and BASIC to be able to deal with Lua's relatively mild level of DWIMminess.
I would use quickjs today for embedding over lua. Everyone know js nowadays and quickjs is really nice. The advantage lua has is library support via Lua rocks. Maybe someone can comment on the quickjs ecosystem?
I have experience of embedding and modifying both QuickJS and Lua. QuickJS is not bad, but Lua is a lot easier and has fewer bugs. JavaScript is a very complicated language under the surface; I think very few people, if any, know and remember all its quirks.
Amazfit's Zepp OS uses quickjs to run 3rd party watchfaces and apps in their smartwatch
I was surprised to find out I'd been wearing javascript on my arm all this time
It sounds like you're saying quickjs is what you'd try if you wanted to embed a language, but you haven't tried embedding quickjs yet?
I think there’s a fork called quickjs-ng that’s actively maintained on GH. Should be able to use it as a lib maybe with some externing.
I’ve also had luck using it in a wasm runtime thanks to quickjs-emscripten. Good if you need sandboxing sans full process isolation.
3 replies →
While QuickJS is nice, JavaScript as a language is much uglier and more complicated than Lua.
[flagged]
Python is arguably easier since you don't need to handle non-native stacks at all; you just have a straightforward mapping of Python operations to C functions that you call with regular arguments, as usual.
With Python's extension API, you have to carefully incref and decref Python values to ensure that you don't either leak memory or deallocate data that's still in use. That's what the Lua stack interface saves you. It's not a call stack, which seems to be what you're thinking of.
4 replies →
It’s easy to embed compared to e.g. python, js or perl, and iff you only push/call/pop and it’s all functions with primitive arguments. Otherwise it’s ~as hard.