top | item 14441492

MoonScript, a programmer friendly language that compiles to Lua

391 points| type0 | 8 years ago |moonscript.org

162 comments

order
[+] leafo|8 years ago|reply
Hey all, I made MoonScript about 6 years ago.

I used it to build a ton of opensource stuff in addition to the company I founded. I use it every day and I'm very happy with how it's turned out. I regret not updating the language more frequently, but I've been busy building a bunch of stuff in it.

The biggest open source project is a web framework for Open Resty: https://github.com/leafo/lapis

It's used for the following open source websites: https://github.com/luarocks/luarocks-site https://github.com/leafo/streak.club

The company I made, https://itch.io also runs on it. There are a a ton of extra Lua modules I've made in MoonScript to facilitate it. Here's a list of my published modules: https://luarocks.org/modules/leafo

I've also completed Ludum Dare 11 times now, making a game each time in MoonScript. I've used https://love2d.org/ as the game engine. You can find the games on my GitHub: https://github.com/leafo?tab=repositories

Feel free to ask any questions

[+] throwaway7645|8 years ago|reply
What's it like being a resident bad@$$?

In all seriousness, what's it like running a company using a language you built or is there only a couple of other employees? Also, I guess you're not worrying about bitrot as you can maintain it yourself and it doesn't need anything other than lua to run correct? Also, why did you originally pick lua. I'm gonna stop and read the articles now :).

[+] kapep|8 years ago|reply
The font you are using looks broken to me. (Win 10, Firefox)

At 100% scaling, every "i" clearly looks like a "1". It reads "MoonScr1pt" for me: https://i.imgur.com/Ti12E5I.png

If I zoom in or out in the browser the i looks ok again.

[+] eriknstr|8 years ago|reply
Dude, this is neat. Itch.io is a great site, I've bought a few things through it.

I like how your HN profile page mentions only MoonScript and not itch.io, though, in that the former is an open source project and the latter is a company :)

[+] nawtacawp|8 years ago|reply
I was just looking at love2d, I don't know much about it. My son is 8 and is very bored with Scratch. A once over the documentation makes me think love2d might be a good fit for a next step from Scratch. How is the love2d community and is it active?
[+] gallerdude|8 years ago|reply
Woah, thanks so much for itch.io - I'm a big fan of indie games and your site is amazing.
[+] shalabhc|8 years ago|reply
Thank you for Moonscript!

> The biggest open source project is a web framework for Open Resty: https://github.com/leafo/lapis

Looks like lapis is ~15K lines. The Howl editor has ~58K lines (including bindings and tests) - making it bigger, technically ;)

[+] rplnt|8 years ago|reply
I have to say that if I see last update in changelog from few years ago I assume the project is dead and one should not use it.
[+] OhSoHumble|8 years ago|reply
If you were to devote more time to MoonScript, what would be the likelihood of including Lua 5.3 compatibility?
[+] mysterydip|8 years ago|reply
This post was timely for me as I'm working on a game project that could benefit greatly from each of the projects you mentioned. Thanks!
[+] sunilkumarc|8 years ago|reply
That's a lot of work you've done alone :)
[+] jlebrech|8 years ago|reply
I'm thinking of creating a blackbox site building service in lua and store people's code in db.
[+] Cyph0n|8 years ago|reply
This is one of @leafo's excellent projects. He has developed a web framework for MoonScript called Lapis. One of the cool things about Lapis is that it runs on top of OpenResty, which is a high performance web server for Lua applications. Lapis is production-ready: it runs his amazing game marketplace, itch.io.
[+] jdonaldson|8 years ago|reply
On a related topic, Haxe now compiles to Lua as well : https://haxe.org/blog/hello-lua/ (disclosure : I'm the author of the lua target)

Back to moonscript/Lua, I've been super impressed with the YAGNI principals of the language. I was originally drawn to LuaJIT and its raw speed, but there's a lot of great things to say about the language and its community.

My goal is to write more Lua for smaller scripting purposes, and use Haxe/Lua for more complex projects, taking advantage of LuaJIT speed in both cases.

[+] mtalantikite|8 years ago|reply
Lapis + MoonScript + OpenResty looks like a lot of fun, so I was just starting to get a local environment running for it and immediately ran into the Lua 5.1 and 5.2+ divergence. For someone who has just been a casual observer of the Lua ecosystem over the years, can someone talk about the community's feelings towards that divergence? The OpenResty docs basically state it's not worth the effort to support anything but Lua 5.1, which at this point is 5 years old and no longer updated.

From someone on the outside that makes me hesitant to spend much effort investing in the ecosystem. Are the libraries fragmented across different versions too? Are there really no plans for an upgrade path, or does everyone just expect to use 5.1 forever?

[+] weberc2|8 years ago|reply
I understand that people love programming in classes, but I really want something like a stripped-down ES6. In particular, I want:

1. Lists and objects/dicts only; objects have no prototypes at all; objects have no first-class methods, but they can have functions as member variables, and those functions can close over other data in the object

2. All function and variable declaration is anonymous (as a consequence of 1); if you want to define a schema for an object, build a function that takes certain arguments and returns an object with the corresponding structure.

3. Coroutines/fibers/etc for async things; no promise/callback hell

4. Type annotations a la Python (not sure how this fits with 2 just yet)

EDIT: I did a bad job of emphasizing this, but syntax is important to me--I want something that looks like:

    var foo = {
        x: [1, 2, 3],
        y: (a, b, c) => {
            var sum = a + b + c;
            sum * sum
        },
    }
Whether or not you agree that syntax should be a relevant criteria is a different matter. :)
[+] fasterthanlime|8 years ago|reply
moonscript powers the itch.io indie marketplace - the original announcement has a quick write-up: http://leafo.net/posts/introducing_itchio.html

After spending years working with Ruby or Java, it was a very nice change of pace. Lapis (leaf's web framework) is crazy good as well: it's easy to write fast code, see this article on coroutines: http://leafo.net/posts/itchio-and-coroutines.html

(disclaimer: I work there with Leaf!)

[+] yowmamasita|8 years ago|reply
Had there been any scaling problems for Lapis-powered apps that you have worked on?
[+] vortico|8 years ago|reply
I love the syntax that Coffeescript-like languages are converging to, like Moonscript, tj's luna (https://github.com/tj/luna) and Pogoscript (http://pogoscript.org/). They fall way on the right of the "computer code vs. human code" spectrum, which is handy when writing applications as quickly as possible rather than focusing on fine details like implementation and performance. It's a shame I don't see it often in the wild, except for Atom and a few others.
[+] Pxtl|8 years ago|reply
Some of the stuff in Moonscript feels a little overdone and magical, like parens-less function calls and the syntactically significant whitespace - but others really feel like they're fixing the gaps in Lua. Moonscript's nice lambda syntax, ternary operator, default local, implicit return, etc.

But I don't think I really needed the ! operator, for example.

[+] bakery2k|8 years ago|reply
fixing the gaps in Lua. Moonscript's [...] default local

Roberto Ierusalimschy, the creator of Lua, believes that "Local by default is wrong." [1].

I don't necessarily agree that local-by-default is inherently wrong, but every implementation of local-by-default that I've seen has had flaws.

It looks like MoonScript is no different - its scoping rules seem to suffer from the same "madness" as CoffeeScript [2].

[1] http://lua-users.org/wiki/LocalByDefault

[2] https://donatstudios.com/CoffeeScript-Madness

[+] PatentTroll|8 years ago|reply
I was on a team that used Lua in production on tens of thousands of machines running 24/7. The Lua interpreter was the weak link in the system, requiring at least daily restarts. Squashed so many bugs over the years, and still found more and more all the time. What I'm saying is, the Lua interpreter itself is flawed and I can't imagine using it as a runtime if I had the chance to avoid it. That said, the language was fun and fast and got the job done. The interpreter could use some work.
[+] yev|8 years ago|reply
I find Lua itself very programmer friendly.
[+] partycoder|8 years ago|reply
Adding superlatives to your stuff is, to me, just noise. e.g: "fast", "simple", "friendly", "lightweight".

I would rather provide conclusive proof, like some side to side comparison of features to illustrate how idiomatic MoonScript is supposedly friendlier than Lua.

Personally I think the changes are not necessarily in the right direction:

For example, what if you have a typo in a variable identifier when assigning a value to a variable? Now you have a new variable. Where to look for the definition of a variable? It depends on what runs first now. That's not friendlier. CoffeeScript made the same mistake in the name of simplicity and it quite frankly doesn't add any value. The time you saved typing "local" will be now consumed several times debugging and code reviewing... and you will have to pay more attention during your code reviews.

Then, removing braces and other delimiters. That's not necessarily better either. Let's remove lane delimiters from streets, traffic signals, stop and yield signs, and let's make it all implicit based on rules you can follow in your head. See? doesn't work.

[+] RyanSquared|8 years ago|reply
> I would rather provide conclusive proof, like some side to side comparison of features to illustrate how idiomatic MoonScript is supposedly friendlier than Lua.

In the reference manual, it is quite literally a side by side comparison. MoonScript code is shown to the left, with Lua to the right. MoonScript provides shortened code with minimal overhead compared to how it would be implemented in Lua, and you can see how by viewing the reference manual.

> For example, what if you have a typo in a variable identifier when assigning a value to a variable? Now you have a new variable. Where to look for the definition of a variable? It depends on what runs first now. That's not friendlier. CoffeeScript made the same mistake in the name of simplicity and it quite frankly doesn't add any value. The time you saved typing "local" will be now consumed several times debugging and code reviewing... and you will have to pay more attention during your code reviews.

This is the same problem with Lua. The best solution that I've found is to have an editor that highlights variables in different colors; once the color has changed (and it should based on if it's similarly named to another variable, so that `asdf` should be a very different color to `asdg`) you know it's a different variable.

> Then, removing braces and other delimiters. That's not necessarily better either. Let's remove lane delimiters from streets, traffic signals, stop and yield signs, and let's make it all implicit based on rules you can follow in your head. See? doesn't work.

Except you can still know when a block ends. Your comparison isn't really fair because it's just a cosmetic change. It's as though stop signs were a square instead of an octogon, not if they were just completely removed.

[+] sattoshi|8 years ago|reply
How are they just noise? If somebody says that something is "fast", it's because it's purpose is to be fast and nothing else. If something says it's lightweight it means it's aim is a minimal size. They are not noise, they are mission statements.
[+] eutropia|8 years ago|reply
Many languages allow for assignment and instantiation on the same statement... I deal with this all the time in ruby and my editor simply highlights vars which aren't used later (quickly leading me to figure out if I had a typo)

As for your traffic example: in many circumstances removing lines and signs makes the roads safer (as reported by the guardian). People pay more attention because of increased uncertainty, and aren't driving (or coding) on autopilot. https://www.theguardian.com/commentisfree/2016/feb/04/remova...

Paying attention is precisely what we're paid to do.

[+] b0rsuk|8 years ago|reply
Side by side: the examples on the landing page have a "Show LUA" button, so you can easily compare.
[+] rweichler|8 years ago|reply
I see it as a toy language. The only person I think would find it useful is leafo himself since he can edit it however he wants. But everyone else should stay away from it. Plain Lua is so much better.
[+] koolba|8 years ago|reply
"Moonscript is like CoffeeScript for Lua"

That's a very succinct description and from skimming the examples, quite apt.

But what I want is Typescript for Lua, specifically to use with Redis. That way I can define interfaces for my keys/values and have static checks on their usage.

[+] shalabhc|8 years ago|reply
Another Moonscript project is https://howl.io - an editor written almost entirely in Moonscript that runs on LuaJIT.
[+] weberc2|8 years ago|reply
How does MoonScript compare to Wren? https://github.com/munificent/wren
[+] nextlevelwizard|8 years ago|reply
System.print("Hello world")

It kind a looks like someone wanted to make actual Java-script. To me these are way too different to even compare, unless you are talking about performance, but then you are just comparing Lua with wren and there seems to already be some benchmarking of these on wren.io

[+] OriginalPenguin|8 years ago|reply
Can this be used instead of Lua with Redis? Is there an example somewhere of that?
[+] leafo|8 years ago|reply
Yup, just pre-compile the code and load it into redis as normal.
[+] k__|8 years ago|reply
Nice!

We need more programming languages with sane syntax.

[+] nirav72|8 years ago|reply
I wonder if this would work with NodeMCU development for esp8266 boards.
[+] nilved|8 years ago|reply
Lua is a great language and MoonScript improves on it even further. I used MoonScript to write a load balancer with OpenResty recently, and World of Warcraft interface code six years ago. :)