17 ms·
MoonScript, a programmer friendly language that compiles to Lua
- vortico 9y agoI love the syntax that Coffeescript-like languages are converging to, like Moonscript, tj's luna (https://github.com/tj/luna https://github.com/tj/luna) and Pogoscript (http://pogoscript.org/ 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.
- plexicle 9y agoThankfully, GitHub starting gutting Coffee from Atom a long time ago. There's still too much in there though.
- vlunkr 9y agoWhile I understand the move to es6 or whatever we're calling it now, a part of me really misses coffeescript. I found it to be very elegant
- penagwin 9y agoI agree - I love coffeescript's syntax. It feels like comparing python to java-esk syntax (I mean without the type checking, etc)
- anotherevan 9y agoAgreed. Coffeescript was excellent lipstick for the pig that is javascript.
- boomlinde 9y agoNot particularly a fan, that analogy is solid. To me, a pig in lipstick seems somewhat more disturbing than one without.
- anotherevan 9y agoI was riffing on an old expression of putting lipstick on a pig. https://en.wikipedia.org/wiki/Lipstick_on_a_pig https://en.wikipedia.org/wiki/Lipstick_on_a_pig
- boomlinde 9y agoI realize that, but the point of the saying is typically that a pig with lipstick is little or no better than without. My point is that Coffeescript makes JS worse. It just adds an additional layer of complexity when you end up debugging the same old JS traps. The saying still holds up, because a pig wearing lipstick could actually be worse than a plain pig.
- anotherevan 9y agoAh, well in that case we are in disagreement. I think Coffeescript is a big improvement. It produces JS code that conforms to The Good Parts™ without having to remember to always add that third equals sign or the var keyword to avoid making a global and other such ridiculous bull-ka-ka. So you end up not debugging the same old JS traps as much because it is a lot harder to write them. (You get to debug shiny new JS traps instead, but there's only so much a good lipstick can do.) But it's fine if you prefer javascript to coffeescript. Tastes differ. Some people like bull-ka-ka. runs away
- twykke 9y agospread some love for moonscript (and its inspiration coffeescript of course, my daily bread-and-butter) - to my mind the best possible syntax for a (dynamic) programming language. python being second place. is it possible to get a tattoo with significant whitespace?
- rattray 9y agoCurious what you might think of LightScript (http://lightscript.org http://lightscript.org) – would love feedback!
- yev 9y agoI find Lua itself very programmer friendly.
- throwaway7645 9y agoAgreed, but it looks like it adds a layer of syntax to give you things like classes without the user having to leverage metatables.
- RyanSquared 9y agoThat is correct. It's also done dynamically so you don't have any external dependencies required when transpiling to Lua code. EDIT: I am not saying this is better - it could certainly be improved or, as is the case with a project of mine, injected into the runtime as a global value. It's just good for running MoonScript alongside Lua.
- pier25 9y agoExcept that arrays start on 1, right?
- Houshalter 9y agoExactly. It's more intuitive and you have less `x-1`'s in your code.
- anonymoushn 9y agoArrays starting at 1 and being closed intervals is mostly just worse than starting at 0 and being half-open intervals. Here's an expression to take an integer b and "mod it" into an interval from a to c, given the normal convention from C++ or Python or whatever where intervals are [a, c): (b-a)%(c-a)+a And here it is in the lua convention where intervals are [a,c]: (b-a)%(c-a+1)+a This is a generalization of what you'd do if you got a really big random integer and you wanted to use it to pick from an array. For that, normally you'd write n % array.length but in Lua you should be careful to write (n % #array) + 1 You can read some other opinion about this here https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- weberc2 9y agoI 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. :)
- RyanSquared 9y agoThis is basically Lua, excluding type annotations. Lua's form of OOP is very strange in that methods aren't bound to a parent context, but instead take the object as a value. For example, `object:method()` is the same as `object.method(object)`, and `function object:method()` is the same as `function object.method(self)` - the only difference being calling the function via `object:method()` is a bit more optimized. There is also a framework with networking, signals, and other cool features called `cqueues` which works based off of coroutines.s You might want to check that out too :)
- Cyph0n 9y agoAnd the size of the Lua runtime is nothing short of beautiful. I have yet to find a use for Lua though, so I'm still waiting for an opportunity to work on something with it.
- RyanSquared 9y agoI find it's used a lot in places you wouldn't expect. I found it used in a car radio, the modem used in my house, and a few other places. It's lightweight if you want to use it on embedded systems (for example, NodeMCU) if you're into that kind of thing.
- fasterthanlime 9y agomoonscript powers the itch.io indie marketplace - the original announcement has a quick write-up: http://leafo.net/posts/introducing_itchio.html 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 http://leafo.net/posts/itchio-and-coroutines.html (disclaimer: I work there with Leaf!)
- yowmamasita 9y agoHad there been any scaling problems for Lapis-powered apps that you have worked on?
- Cyph0n 9y agoThis 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.
- leggomylibro 9y ago+1 for Lapis - it's fairly barebones, but it's also nice and simple. You can also code it in Lua, if you feel more comfortable with that. I was looking into using it to make a site for hosting Love2D games which would optionally run right in the browser, because lua rocks, but I got distracted with other things.
- partycoder 9y agoAdding 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 9y ago> 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.
- leafo 9y agoHey 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 https://github.com/leafo/lapis It's used for the following open source websites: https://github.com/luarocks/luarocks-site https://github.com/luarocks/luarocks-site https://github.com/leafo/streak.club https://github.com/leafo/streak.club The company I made, https://itch.io 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 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/ https://love2d.org/ as the game engine. You can find the games on my GitHub: https://github.com/leafo?tab=repositories https://github.com/leafo?tab=repositories Feel free to ask any questions
- vanderZwan 9y agoAre you aware that TIC-80 supports moonscript? It's one of the better PICO-8 "clones" out there. https://nesbox.itch.io/tic https://nesbox.itch.io/tic https://github.com/nesbox/tic.computer/wiki#cartridge-metadata https://github.com/nesbox/tic.computer/wiki#cartridge-metada...
- ricardobeat 9y agoIs that open source? I'm wondering if it uses SDL or a similar library - binaries look pretty small.
- OriginalPenguin 9y agoCan this be used instead of Lua with Redis? Is there an example somewhere of that?
- bobwaycott 9y agoCheck out https://github.com/jondeandres/moon-redis https://github.com/jondeandres/moon-redis
- bpicolo 9y agoPretty sure he means redis scripting https://redis.io/commands/eval https://redis.io/commands/eval
- OriginalPenguin 9y agoYes, that's what I meant. Thanks!
- leafo 9y agoYup, just pre-compile the code and load it into redis as normal.
- stdbrouw 9y agoHere's an example of a job runner (≈ cron) in Redis and MoonScript: https://github.com/debrouwere/jobs/tree/master/src https://github.com/debrouwere/jobs/tree/master/src. I don't maintain it anymore, but it should give you an idea of how MoonScript can make Redis scripting a whole lot less tedious.
- k__ 9y agoNice! We need more programming languages with sane syntax.
- mtalantikite 9y agoLapis + 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?
- alexforster 9y agoI believe this is because LuaJIT is 5.1-only.
- anonymoushn 9y agoPeople expect to use luajit forever.
- scythe 9y agoThe reason is that the _ENV feature added in 5.2 would significantly slow down LuaJIT if it were supported. It's possible that Luac and LuaJIT will re-converge when Lua 6.0 is released, but arguments about this between Mike Pall amd Roberto Ierusalimschy have been unproductive so far. Until then, LuaJIT compiles Lua 5.1 with support for a few 5.2 and 5.3 features, particularly goto.
- rweichler 9y agoYou have any references to these arguments between the two gods?
- akavel 9y agoTotally not a concrete link, sorry, but - in a video from one of Lua conferences, I've seen Roberto mention in some polite yet clear way that talks with Mike which they had had always come to a standstill on something - at least that's how I recall it. On the other hand, since 2015, Mike was looking to pass luajit development on to someone else - so with this, situation could possibly change in the end. But I'm not sure what's the current status of this search; I seem to recall CloudFlare was reported to be in talks, but I don't know how it all ended - or if it's still unresolved.
- nilved 9y agoLua 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. :)
- shalabhc 9y agoAnother Moonscript project is https://howl.io https://howl.io - an editor written almost entirely in Moonscript that runs on LuaJIT.
- jdonaldson 9y agoOn a related topic, Haxe now compiles to Lua as well : https://haxe.org/blog/hello-lua/ 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.
- baldfat 9y agoThank you. The more I use Haxe the more I love it and I have compiled to Luna and it worked flawlessly. Thank you
- jdonaldson 9y agoIt makes my day to hear this. Glad it is useful!
- koolba 9y ago"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.
- anonfunction 9y agoCheck out Haxe: https://haxe.org/blog/hello-lua/ https://haxe.org/blog/hello-lua/
- leafo 9y agoTyped Lua might be worth checking out: https://github.com/andremm/typedlua https://github.com/andremm/typedlua (disclaimer: I haven't used it yet)
- PatentTroll 9y agoI 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.
- 77pt77 9y agoEver used luaJIT?
- PatentTroll 9y agoNo, I think we played around with it but decided to stick with the known quantity of the mainline interpreter, 'devil you know' and all. Because the types of bugs we found were not readily apparent at first, the types of things that would only manifest in statistics accords thousands of machines on 24/7, so pushing a new interpreter out was seen as too risky
- worrydream 9y agoThis page lists every known bug in the Lua interpreter for the last 14 years, along with its fix: https://www.lua.org/bugs.html https://www.lua.org/bugs.html The average is 8 bugs per year, most fairly obscure. Every Lua release fixes all known bugs. Roberto, the chief architect, is kind of fanatical about quality: https://www.youtube.com/watch?v=yU5QNKpATxk https://www.youtube.com/watch?v=yU5QNKpATxk I do not believe the interpreter is as flawed as you claim.
- lifthrasiir 9y agoI think Lua interpreter itself is fairly stable. But the problem is that it lacks the proper mechanism for language upgrade or deprecation---for example we have found a (undocumented) bug affecting Lua 5.1.x which has been silently fixed in 5.2, but we were stuck at 5.1 so we had to fork the interpreter. That kind of things. The development process of Lua is definitely flawed in my humble opinion.
- weberc2 9y agoHow does MoonScript compare to Wren? https://github.com/munificent/wren https://github.com/munificent/wren
- nextlevelwizard 9y agoSystem.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
- Pxtl 9y agoSome 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 9y agofixing 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 http://lua-users.org/wiki/LocalByDefault [2] https://donatstudios.com/CoffeeScript-Madness https://donatstudios.com/CoffeeScript-Madness
- allover 9y agoEugh, I know you aren't defending that CoffeeScript article, but it hugely exaggerates the 'problem' by not acknowledging module scope (see the comments).
- cosarara97 9y agoYou can use 'local' to have sane scoping (shadowing) in moonscript though: -- will print: -- 15 -- 0 -- 15 -- 10 y = 0 goodfun = (x) -> local y y = 10 y + x badfun = (x) -> y = 10 y + x print(goodfun(5)) print(y) print(badfun(5)) print(y)
- Pxtl 9y agoHonestly, it seems like implicit variable declaration is a bad idea. Some minimal keyword to indicate "this is a new variable in this scope" seems necessary for sane scoping. It nicely prevents a class of bugs of "oops I made a typo in that assignment and created a new variable" gets caught.
- lafytahoe 9y agoLua is a programmer friendly language. It's just not ruby, which moonscript tries to provide. Not all languages must be ruby-esque.
- nirav72 9y agoI wonder if this would work with NodeMCU development for esp8266 boards.