News for hackers. Stuff that matters.
Re:Tables by oweiler on Wednesday September 12, 2018 @12:01PM (#17970129)
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.

Re:Tables by zeotroph on Wednesday September 12, 2018 @12:44PM (#17970598)
> 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.

Re:Tables by wruza on Thursday September 13, 2018 @10:05AM (#17978689)
Luvit 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.

Re:Tables by ufo on Wednesday September 12, 2018 @07:13PM (#17974378)
I 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.
Re:Tables by sdegutis on Wednesday September 12, 2018 @12:12PM (#17970232)
Lua 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/

Re:Tables by vvanders on Wednesday September 12, 2018 @01:08PM (#17970851)
> 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-javascri...

[2] https://www.freelists.org/post/luajit/Looking-for-new-LuaJIT...

Re:Tables by zeotroph on Wednesday September 12, 2018 @12:51PM (#17970675)
> 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.

Re:Tables by engineer331 on Wednesday September 12, 2018 @11:16PM (#17975686)
You 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/

[2]: http://wiki.squirrel-lang.org/mainsite/Wiki/default.aspx/Squ...

[3]: https://developer.valvesoftware.com/wiki/Squirrel

Re:Tables by mingodad on Thursday September 13, 2018 @05:33AM (#17977235)
There 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

Re:Tables by wruza on Thursday September 13, 2018 @10:18AM (#17978773)
>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?

Re:Tables by vmsp on Wednesday September 12, 2018 @12:34PM (#17970477)
What JavaScript interpreter do you use for embedding? I know of MuJS [1] but it only supports ES5.

[1] https://mujs.com/

Re:Tables by dividuum on Wednesday September 12, 2018 @06:53PM (#17974247)
There's duktape (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.
Re:Tables by sdegutis on Wednesday September 12, 2018 @12:35PM (#17970493)
My JS-embedded apps only target macOS so I use Apple's builtin JavaScriptCore framework.
Re:Tables by nikki93 on Wednesday September 12, 2018 @12:52PM (#17970700)
In 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)

Re:Tables by sdegutis on Wednesday September 12, 2018 @12:59PM (#17970773)
Maybe, 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.
Re:Tables by nikki93 on Wednesday September 12, 2018 @01:15PM (#17970914)
Yeah 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.

Re:Tables by sdegutis on Wednesday September 12, 2018 @01:18PM (#17970937)
If 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.
Re:Tables by armitron on Wednesday September 12, 2018 @01:42PM (#17971127)
Love2d can use luajit or plain lua.
Re:Tables by nikki93 on Wednesday September 12, 2018 @04:28PM (#17972926)
perf is important but I also want user scriptability (as part of the actual app feature(s)). Love2d uses LuaJIT (it does use the C API to bind its native calls rather than the FFI -- but actually that has better perf when not JIT'ing).
Re:Tables by Immortalin on Wednesday September 12, 2018 @12:38PM (#17970533)
If you are interested, join my newsletter for Lua:

https://luadigest.immortalin.com

Difficult for Lua to reach the same momentum as other languages since it's mostly embedded but every bit helps.

Re:Tables by AnIdiotOnTheNet on Wednesday September 12, 2018 @03:18PM (#17972152)
You 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.

Re:Tables by Immortalin on Wednesday September 12, 2018 @04:54PM (#17973207)
I 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.

Re:Tables by AnIdiotOnTheNet on Wednesday September 12, 2018 @07:35PM (#17974553)
Given Lua's age and use in so many projects, I was under the impression that it was somewhat stable.

Basically, my interest in Lua is this: I'd like to build a personal computing environment that is oriented towards end-user empowerment the way I remember them being in the pre-web era. To that end, employing a relatively simple interpreted language to build as much of the environment as possible is desired such that the end user is able to read and modify large portions of it, as well as create their own tools. Something on the level of Visual Basic or HyperCard would be useful for the GUI portions, and Lua is popular enough to have a lot of learning resources available, so it was an option I was considering.

Re:Tables by Immortalin on Wednesday September 12, 2018 @08:23PM (#17974825)
It is fairly stable in terms of syntax. Just that features like Unicode support etc. tend to be difficult to implement without deep changes. For OS dev, look into Node9 and https://www.lua.org/wshop13/Cormack.pdf

There have been quite a few attempts at building OSes with Lua as main system/userland language. There are very few Lua implementations that can bootstrap so you still need a bit of non-Lua code as glue for the interpreter bits if not for juggling pointers.

Re:Tables by oweiler on Wednesday September 12, 2018 @12:41PM (#17970557)
Thank 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.
Re:Tables by Immortalin on Wednesday September 12, 2018 @01:03PM (#17970807)
If 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

Re:Tables by ungzd on Wednesday September 12, 2018 @03:17PM (#17972129)
> 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.

Re:Tables by vvanders on Wednesday September 12, 2018 @03:35PM (#17972343)
> 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.

Re:Tables by fb03 on Wednesday September 12, 2018 @08:32PM (#17974874)
what game?
Re:Tables by rebolek on Wednesday September 12, 2018 @03:37PM (#17972365)
> Who cares if embedded runtime is 100 Kb or 2000 Kb?

That's a joke, right?

Re:Tables by jxub on Wednesday September 12, 2018 @02:33PM (#17971648)
So... You've yet to fall in Löve?
Re:Tables by enriquto on Wednesday September 12, 2018 @01:46PM (#17971170)
> 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.

Re:Tables by Annatar on Thursday September 13, 2018 @02:05AM (#17976405)
pip 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.
Re:Tables by pmontra on Thursday September 13, 2018 @02:30AM (#17976487)
I 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.)

Re:Tables by Annatar on Thursday September 13, 2018 @02:42AM (#17976541)
"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.

Re:Tables by pmontra on Friday September 14, 2018 @02:08AM (#17985041)
You're probably not the author of all those packages but if you are, did you also create .deb for people using distributions derived from Debian?

If not, do you keep the RPMs updated and did you ask the authors to create RPMs instead? What did they answer you?

Re:Tables by Annatar on Friday September 14, 2018 @03:44AM (#17985436)
I did not create .deb's because my client uses a RHEL-based operating system. The point is that I had to do it because CRAN simply decided to re-invent the wheel. I did not contact every single one of the 170 authors to create RPM's: if they really wanted to, they would have done that by now, not to mention it would be impractical for me to contact 170 people and attempt to explain to them what it means to design for operational maintainability.

Yes, I maintain the RPM's. It's easy because I always build .src.rpm's (SRPM's) by default, and a binary .rpm (RPM) ends up being a product of one of the steps in that process (`rpmbuild --clean -ba ...`).

But all of that is almost irrelevant. The relevant bit is that if done correctly, if done cleanly, as operating system packages, organizations need neither Docker nor "infrastructure as code" (copious amounts of amateurishly written glue in a scripting language) and the software is easy and fast to install and maintain -- for both system administrators and end users. I even do very large scale configuration management with operating system packaging, rather than with applications like CFengine, Chef, or Puppet.