6 ms·
Started coding in Lua 2 months ago and instantly fell in love. Higher order functions, coroutines, the ability to return multiple values from a function, no co
by oweiler 8y ago
Started coding in Lua 2 months ago and instantly fell in love.
Higher order functions, coroutines, the ability to return multiple values from a function, no coercion on comparison operators make coding in Lua a breeze.
You can learn most of the language within a day.
Ofc not everything is perfect: The package ecosystem is growing but still small compared to other languages.
Anonymous function definitions are pretty noisy.
Still I think it's one of the best designed languages you can find.
- sdegutis 8y agoLua is amazing in that it is very small, portable, and easily embeddable. But aside from those three things, Lua is semantically almost identical to modern JavaScript. I've embedded both and used them heavily in my various window managers, and these days I personally recommend embedding JavaScript over Lua if possible. But when a small, portable and lightweight language is needed, there's also Sparkling[1], which is like the best ideas of JavaScript with the minimal footprint and portability of Lua. [1]: http://h2co3.github.io/sparkling/ http://h2co3.github.io/sparkling/
- vmsp 8y agoWhat JavaScript interpreter do you use for embedding? I know of MuJS [1] but it only supports ES5. [1] https://mujs.com/ https://mujs.com/
- sdegutis 8y agoMy JS-embedded apps only target macOS so I use Apple's builtin JavaScriptCore framework.
- nikki93 8y agoIn my experience LuaJIT in interpreter only mode has better performance than using JSC (you can’t use JIT in JSC either — only WKWebViews can JIT). (edit: sorry this is regarding iOS)
- sdegutis 8y agoMaybe, but my use-cases (window manager and other automation stuff) don't really have a strong need for speed or high performance. Mostly it just sits there idle 99% of the time and runs callbacks quicker than the UI that it manipulates is visibly updated.
- nikki93 8y agoYeah I think it does end up boiling down a lot to use cases because the big differences b/w Lua and JS are in availability of libs / integration and perf. In my case I do a lot of 2d graphics where love2d.org is available and perf is important. :) C interop is also really important, and LuaJIT C FFI is waaaaay nicer to use than JSC C API. I’ve ended up doing a lot of JS with React Native for “app-y” mobile apps though.
- sdegutis 8y agoIf perf is important, I'm surprised you're using Love2d and not just using C++ with SDL and Box2d directly. Afaik Love2d just uses vanilla Lua (and not LuaJIT) which, while faster than similar languages, is still pretty wasteful of cycles when high perf is needed.
- dividuum 8y agoThere's duktape (https://duktape.org/ https://duktape.org/), which, from skipping over the documentation seems very similar to Lua when it comes to embedding: It also uses the stack based approach. Looks like there's some ES6/7 support.
- zeotroph 8y ago> Sparkling All these "Let's do Lua, but right" languages fill me with both hope AND dread. This also shows what Lua could have become if a few more bold decisions were made. But I guess without a large commercial entity behind it, that was inevitable. Is there list of lua-ish (especially wrt. speed and easy C integration) languages somewhere? I did not know this one for example.
- engineer331 8y agoYou might want to check out Squirrel[1]. It has some major differences when compared to Lua[2], such as a C-style syntax and true objects, but like Lua is known for easy embedding in C and C++. The Source Engine includes Squirrel as one of its supported scripting languages[3], and it's used in non-gaming applications such as the Code::Blocks IDE. [1]: http://squirrel-lang.org/ http://squirrel-lang.org/ [2]: http://wiki.squirrel-lang.org/mainsite/Wiki/default.aspx/SquirrelWiki/Lua%20Compared%20to%20Squirrel.html http://wiki.squirrel-lang.org/mainsite/Wiki/default.aspx/Squ... [3]: https://developer.valvesoftware.com/wiki/Squirrel https://developer.valvesoftware.com/wiki/Squirrel
- mingodad 8y agoThere is also a squirrel fork SquiLu[1] that add some Lua code (like pattern matching, some stdlib), extend it with string IO, have several extensions (sqlite3, http server, mpdecimal, axtls, curl, ...), accept a subset of Javascript/Java/C/C++, ... [1]:https://github.com/mingodad/squilu https://github.com/mingodad/squilu
- vvanders 8y ago> Lua is semantically almost identical to modern JavaScript. Having spent a lot of time looking pretty hard at Lua, LuaJIT, and embeddedable variants of JS(duktape and the like) I think that's a bit of a stretch. It's pretty trivial to induce JS memory leaks[1] that can be brutal on embedded platforms. We had a prototype project written in JS and Lua, same functionality but hit issues like this pretty often. Like most memory leaks they weren't straightforward to track down as well. For my money LuaJIT still reigns supreme despite the fact that it's not under active development any more[2]. [1] http://point.davidglasser.net/2013/06/27/surprising-javascript-memory-leak.html http://point.davidglasser.net/2013/06/27/surprising-javascri... [2] https://www.freelists.org/post/luajit/Looking-for-new-LuaJIT-maintainers https://www.freelists.org/post/luajit/Looking-for-new-LuaJIT...
- wruza 8y ago>almost identical to modern JavaScript What do you mean by ‘almost’? You cannot have fair separate threads of execution or substitute function’s global environment in javascript, but this is the other way ‘almost’. What features does js have beyond syntactic sugar and second-hand techniques?
- Immortalin 8y agoIf you are interested, join my newsletter for Lua: https://luadigest.immortalin.com https://luadigest.immortalin.com Difficult for Lua to reach the same momentum as other languages since it's mostly embedded but every bit helps.
- oweiler 8y agoThank you, I've joined your newsletter. This is exactly what Lua is currently lacking. When I have more time, I'll probably do some writeups on Lua, especially CI/CD and developing libraries.
- Immortalin 8y agoIf you are willing, drop me an email with anything you want me to publish as e.g. a contributing editorial etc. You can reach me at Luadigest at <my username> .com
- AnIdiotOnTheNet 8y agoYou seem like you might know the answer to this question that I've had about Lua: I can find games, window managers, embedded devices, and a bunch of other stuff that can be scripted with Lua, but there doesn't seem to be anything like a Visual Basic equivalent that lets you layout a GUI graphically and tie the controls and events together with Lua, at least not for native applications. Why is that? It seems like it'd be a good fit.
- Immortalin 8y agoI have some familiarity with GUI builders. In general, those tend to be targeted at end-user consumer software like desktop applications, web services, and mobile apps. For game development and embedded systems, there is a strong preference for custom, bespoke stuff. It's especially bad in embedded systems which never had an open source "standard library" till Arduino. The ecosystem is highly fragmented compared to e.g. your average smartphone and PC. An industrial control panel UI using Material Design on a high end ARM core won't necessarily run on a health tracker powered by a STM32 or Atmel chip. For gaming, the story is a bit different. Lua is heavily used there but because every game is different, the GUI parts tend to be done with custom designs. The type of UI builders used in Game Development is rather different than the sort used in desktop software but there are plenty. If you are looking for a minimal resource consumption language with good cross-platform rapid UI development as a first-class priority, I recommend you check out the Red programming language. For Lua, it's use as a mainstream application development language is still in it's early stages. The language follows the mantra of move fast and break things so backwards compatibility isn't a top priority and this can be an issue in evergreen codebases like web apps (unless you are willing to lock to a specific version). Most web servers (most famously OpenResty, a Lua NGINX hybrid) are still on 5.1 due to LuaJIT.
- zeotroph 8y ago> The package ecosystem is growing That is a nice euphemism. The lack of something even remotely resembling a standard library is what keeps me from using lua more than I absolutely have to. Because more complex constructs can be created so easily in Lua everybody is happily copy/pasting half baked stuff from the web. That means there is no common style which might make it consistent across code bases so Lua remains a "Bring Your Own" language. No proper arrays, no easy exceptions, no easily recognizable classes ("but it is so easy with setmetatable etc."), iterators, prettyprint... Plus the various annoyances, such as nil access not being an error, no += (I read all the reasons against it), weird "false" concept, that tables are - if you look closely - neither arrays nor dictionaries, the "require" imports are not modules but more akin #include. In my opinion Lua 6 should drop some historic weirdness (~=!) and make the core language more in line with JS or Python and provide a standard library - even if components there sacrifice some of the holy performance.
- ufo 8y agoI dont understand what you mean by comparing require with include. Lua's require only loads each module once, and doesn't introduce any new variables to the local scope.
- wruza 8y agoLuvit is node-copied environment, which nils “no library” downside. Lua doesn’t push it, but it is there and even works. As of no classes or ‘weird’ parts, js has more rich history of bullshit included, not included or misbehaved than any language ever. I’m not going to enumerate these here. You just get used to it and now can’t stand it in others. Js prototyping is much dumber though, so it could be hacked by 5-minute newbies easily, unlike mt/index magic. But there is no such thing like ‘being in line’ with javascript, since it draws no line. You can write a parser that makes Lua js-like (or even better) in a couple of hours, but that woudn’t make it popular. Including it into a browser would though. But browsers still resist to include anything viable like RxRS scheme-likes at least that could be transpilation target, repeating that unsmart ‘maintaining complexity’ argument. You’re stuck with js and that’s why rants go all the way. If it had enough concepts, there would be less rants and more transpilers, but it is dumb af and oriented on end-developers rather than on library, system or metadevelopers. At least wasm is a hope, but it was not seen seriously yet in this regard. Ps. require() is a regular one-time module-load routine, nothing to do with #include.
- enriquto 8y ago> not everything is perfect: The package ecosystem is growing but still small compared to other languages. This is a positive point to me. I love python but hate pip and stuff.
- Annatar 8y agopip really sucks, in fact any packaging system discrete to its programming language sucks, because it bypasses the operating system's software management subsytem (pkgadd, pkgsrc, rpm, et cetera). Then one has to have an imaging system like Docker to work around that, so developer's convenience leads to one bad decision after another in the operational repeatability space.
- pmontra 8y agoI used to install Ruby gems with apt circa 10 years ago but quickly gave up because they were outdated and I couldn't have different versions in different projects. Same with Python later on. Things like virtualenv solve the problem of having multiple versions of the same package or interpreter in different projects. Rpm and apt can't do that, that's why developers are using package managers for virtually every language. Furthermore creating native packages for even the major distros and LTS releases is too difficult. There are also tools like asdf that handle multiple languages (and databases!) Docker solves the problem of distributing the application. Virtualenv is quite weak about that. Docker can also be used to create separate environments on the development machine and install packages without virtualenv. We still need pip because nobody creates native packages. The same reasoning applies to every language I'm working with (Ruby, Node, Elixir, PHP.)
- Annatar 8y ago"Furthermore creating native packages for even the major distros and LTS releases is too difficult." This is simply not correct: the truth is that people are lazy and don't want to spend the required time reading the documentation, the first thing a real engineer does. Instead, they just want instant gratification. They just want to hack. OS packaging is actually quite easy. "We still need pip because nobody creates native packages." I created over 170 CRAN R packages as RPM's. Was it time consuming? You bet! But now it's done correctly. Now it's done cleanly. Now I don't need nonsense like Docker, and I could even plug them all directly into Kickstart and have Kickstart spit out ready to serve systems with a rich R environment on them. With no scripting or any code. Just because I made RPM's, the client now has an architecturaly simple application ecosystem. Simple is robust.
- jxub 8y agoSo... You've yet to fall in Löve?
- ungzd 8y ago> Higher order functions, coroutines, the ability to return multiple values from a function These features are in almost any language nowadays, including most of languages that AOT-compile to native code. Well, maybe without multiple returned values, with tuples instead, but this is the same thing, especially if there's some primitive destructuring support. Type coercion for comparison is quite rare too, even js has `===`. But no standard library at all, so everyone brings his own incompatible hacks (by copy-pasting snippets) and processes lists (hashes emulating lists because there are no real lists) with `for` loop. Even with `for` loop it's not that obvious how to loop over list. I tried writing in Lua and can't stand it at all, even JS feels much nicer. Lua is minimalism for sake of minimalism, and it heavily hampers practicality. Easily embeddable? Who cares if embedded runtime is 100 Kb or 2000 Kb? Well, it might be a good language if comparing it to Basic from 80s home computers, so it's used in PICO-8.
- vvanders 8y ago> Who cares if embedded runtime is 100 Kb or 2000 Kb? We ran Lua on the PSP with 8MB of system memory inside a pre-allocated block of 400kb. Did the whole game logic and state management with no hiccups(and this was before LuaJIT). Not everything is desktop scale, lots of applications in spaces like routers, wearables and other constrained devices. I've also seen few langauges handle coroutines and clean and simple as Lua does them.
- fb03 8y agowhat game?
- rebolek 8y ago> Who cares if embedded runtime is 100 Kb or 2000 Kb? That's a joke, right?