12 ms·
MoonScript: Dynamic scripting language that compiles into Lua
- ARandomerDude 7y agoThe syntax nostalgically reminds me of CoffeeScript, one of my favorite languages.
- vortico 7y ago>The syntax of MoonScript has been heavily inspired by the syntax of CoffeeScript. MoonScript is CoffeeScript for Lua.
- andai 7y agoWhat a beautiful website.
- toastal 7y agoI used this playing with a Lapis project years ago. It very much fit the zeitgeist in the wake CoffeeScript's popularity. Although usable, it feels a bit dated now and a product of its time. The zeitgeist now requires static typing.
- anonymoushn 7y agoThere's TypedLua for this I suppose.
- mrtnpwn 7y agoSadly the active development stopped, but there's an attempt to bring it back by one of the maintainers of LuaRocks. https://github.com/hishamhm/tl https://github.com/hishamhm/tl
- mhd 7y agoThe good thing about playing to fashion is that you just have to wait for things to cycle.
- toastal 7y agoI'm unsure of this. It seems the jury's pretty out on typed == good, but we'll see in 10 years.
- marcosdumay 7y agoFashion only cycles on equivalent choices. Some stuff are better or worse than the alternatives, so they stick either in use or out of it. Types are one of those things that will stick in use. We will also probably see a wild diversity of type systems in experimental languages, as there is very likely one better than everything we use today.
- mhd 7y agoContradicts history, but let's just see.
- boomlinde 7y ago> Fashion only cycles on equivalent choices. Some stuff are better or worse than the alternatives, so they stick either in use or out of it. Even if that is true, there are potentially a lot of dimensions to consider in solving the problem of what is better or worse. Some of these dimensions, or where in that dimension what-is-better falls, take a long time to discover and are different for different problem spaces. Sometimes you think you've got it right only to learn that you were wrong much later. But it isn't true. Fashion is by any indication only loosely concerned with utility and sometimes settles on downright masochistic flavors-of-the-day.
- JNRowe 7y agoI love moonscript, it makes lua feel so much more usable for me. Admittedly, I'm mostly only using it for convenience in configuring apps(such as my WM¹/video player²/etc). If you want to see a large-ish example of what you can do with moonscript the howl editor³ is a great example. It is also a nice extensible editor in its own right, including a very usable vi mode. 1. https://awesomewm.org/ https://awesomewm.org/ 2. https://mpv.io/ https://mpv.io/ 3. https://howl.io/ https://howl.io/
- chatmasta 7y agoOff topic, but just curious, what makes you choose mpv over VLC?
- JNRowe 7y agoNo particularly good reason. I have no use for the vlc gui, so mpv is fine for me. At a push I'd perhaps say the lighter dependency stack is a plus, but if mpv didn't exist I'd probably install vlc without thinking about it. FWIW, apt wants me to install 36 new packages for vlc even with --no-install-recommends. edit: Or - I guess - some other scriptable media player, as being extensible is the thing that matters to me. Unless someone magically matches my quirks with their non-scriptable player ;)
- wiradikusuma 7y agoSo this is like CoffeeScript that transpiles to JavaScipt? Does anyone know if I can use the generated Lua in Redis?
- NieDzejkob 7y ago> Because it compiles right into Lua code, it is completely compatible with alternative Lua implementations like LuaJIT, and it is also compatible with all existing Lua code and libraries. It would seem that there is no reason you couldn't.
- klibertp 7y agoYes, you can - I use it with Awesome WM, and with OpenResty/Nginx, and it works fine. MS compiles to pretty straightforward Lua and doesn't include any code that would make it hard to run as an embedded scripting language.
- meowface 7y agoI love everything about MoonScript except for that damn backslash. I think it's much nicer to use than Lua, but it still bugs me, bikeshedding be damned. The asymmetry, the fact that no other language (that I know of) uses it for a similar purpose, just the look of it in between text... I once came close to trying to create a near-identical fork of the project which changed the backslash to something else, but I figured it'd be pretty pointless. I know I'm definitely not the only one who dislikes it, at least.
- MaxBarraclough 7y agoYou could create a new language that compiles to MoonScript ;-P
- klibertp 7y ago> I know I'm definitely not the only one who dislikes it, at least. You're not. In my fork, I plan to replace `\` with `:` and `:` with `=`, so it's closer to Lua, and less irritating to look at. I need to figure out how to code that while retaining some backward compatibility, but "fixing" this is one of the major goals of my fork.
- nonbirithm 7y agoThe obscure Japan-only language Hot Soup Processor used backslash as mod. http://www.onionsoft.net/hsp/v33/doclib/hspprog.htm#EXPRESSION http://www.onionsoft.net/hsp/v33/doclib/hspprog.htm#EXPRESSI... I also hate it (along with HSP in general). Anything that exists outside the grain of programming language conventions so baked in as basic arithmetic operators throws me off.
- eggy 7y agoBeing a J programmer [1], the order or placement of ASCII characters does not bother me, so I think it's about familiarity, habit and ability to see past the syntax. [1] https://www.jsoftware.com/#/ https://www.jsoftware.com/#/
- hombre_fatal 7y agoAfter years of people saying things like they wish they had Lua in the browser instead of "awful" JS, I finally used Lua for the first time writing games with Pico8 (https://www.lexaloffle.com/pico-8.php https://www.lexaloffle.com/pico-8.php). I found Lua to be so bare-bones and even quirky that I yearned for the expressiveness of C. I was so unimpressed and miserable working with it that I wondered if these people in the wild who supposedly love Lua have used another programming language in the past 15 years. So, with that said, MoonScript looks essential.
- chubot 7y agoThat was my experience with it too. I read the "Programming in Lua" book from cover to cover 10 years ago, and it remains one of my favorite programming books. There's a lot of great information in that book (not just about Lua). And I read a lot of their academic papers which taught me a lot about PL design and implementation. However whenever I try to program in Lua it feels both impoverished and verbose compared to Python. People complain about runtime errors in Python but Lua has even more of them. And the libraries are significantly worse for the same task.
- chii 7y ago> I found Lua to be so bare-bones that's a design feature. Though I do hate the 1-based indexing...
- rs23296008n1 7y agoCertainly makes calculations annoying when referring to indices. Not a showstopper but its a niggle nonetheless.
- seibelj 7y agoI love lua but the 1-based indexing is the worst decision of all. Just makes it an odd-duck when bouncing between languages.
- rogual 7y ago
- fctorial 7y ago> one of the fastest scripting languages Isn't nodejs faster
- iscoelho 7y agoLuaJIT is considerably faster in pure CPU benchmarks than JavaScript. It is also faster than C in some cases unless you are hand optimizing your assembly. See: https://gist.github.com/spion/3049314 https://gist.github.com/spion/3049314 https://en.sfml-dev.org/forums/index.php?topic=18260.15 https://en.sfml-dev.org/forums/index.php?topic=18260.15
- rplnt 7y agoYour quote doesn't even say it's the fastest?
- pansa2 7y agoDepends what sort of code you’re running. LuaJIT is a tracing JIT - it’s great for code which runs the same way over-and-over, but has trouble with unpredictable branches. V8 does a much better job than LuaJIT for things like a loop containing an if/else with a 50:50 condition. Overall, the fastest dynamic language JITs are probably V8 and other JavaScript runtimes - it’s worth noting that none of these use LuaJIT-style tracing.
- samatman 7y agoI wish Mike Pall had stuck around long enough to land hyperblock scheduling :/ https://github.com/LuaJIT/LuaJIT/issues/37/ https://github.com/LuaJIT/LuaJIT/issues/37/ That and the quad-color garbage collector would ensure LuaJIT's dominance for many years to come. The quad-color is well described, and someone might successfully implement it at some point; I doubt there's another human alive who could implement hyperblock scheduling. I'd love to be wrong.
- ksec 7y agoAt least he is still on LuaJiT mailing list. Does anyone know what he is currently working on ?
- maxpert 7y agoSo basically a coffee script for Lua. IDK I have mixed feelings for such transpilers. However I would appreciate one with generics for Go.
- rplnt 7y agoThere is this for example https://github.com/cheekybits/genny https://github.com/cheekybits/genny However, I couldn't justify relying on such tooling for my projects...
- s_gourichon 7y agoPerhaps an opportunity to mention Nim. Similar time. Nim is unrelated to lua. Nim syntax is close to Python. https://nim-lang.org/ https://nim-lang.org/ Efficient, expressive, elegant Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula.
- 7thaccount 7y agoAnd it transpiles to C or JavaScript before being compiled on whatever.
- monadic2 7y agoIt is not memory safe, correct?
- beagle3 7y agoMost of it is. You can do a lot without touching any unsafe parts. It compiles down to JavaScript (which is memory safe), or C / C++ / Objective-C (which aren't). C FFI is unsafe, as well as taking an address of something; but you rarely need these things unless you are already interfacing with unsafe C code. It does not, however, delineate unsafe parts into an unsafe{} scope the way Rust does.
- JNRowe 7y agoAm I the only person who finds "nim is python-y" an odd description? I often think that even "perl with off-side rule" would make more sense, given the variety of ways you can express many concepts in nim(TWMTOWTDI) and number of sigils. I get that the stdlib is clearly inspired by python¹, and that using a reST-ish subset for documentation is Python-y. Beyond that surface scratch the comparison just falls apart, and often seems to end up as a pointless sticking point when introducing co-workers to nim. You can't even ignore the idea, as the moment they crack the awesome Nim in Action book or the official docs they're immediately shown it. 1. down to being able to just guess module names in a few circumstances.
- 7y ago
- tfcat 7y agoI love the idea of Moonscript but, is this weird to anyone else: - class attributes are mutable and shared across all instances!? - to give an instance its own state you gotta define attributes in the constructor In that case, there's OOP modules for raw Lua that work well. I'd prefer to stick with Lua.
- klibertp 7y agoYes, the class stuff in MS is plain wrong, all of it (except `=>`, maybe). In my fork, I plan to drop it all. The thing is, the prototypal, copy-on-write nature of Lua object orientation is not a disability, there's no need to "fix" it, the model is powerful enough as it is, it just needs to be used well. Some years ago I learned Io - another prototype-based language, similar to Self - and I was amazed at how expressive it is based on a very small set of core primitives. All the primitives, including async calls in coroutines, are either built-in in Lua or are trivially implemented with a small code transformation.
- chatmasta 7y agoMoonScript reminds me of CoffeeScript in this regard. Lua and JS are both prototypical languages, which is a feature, not a bug. Putting some `class` syntactic sugar around it helps initially, but also causes confusion when it doesn't act like a traditional OOP class.
- Quenty 7y agoLua isn’t really a prototypical language, it’s a build-your-own-class system. Metatables help facilitate this. You can do classic OOP if you want.
- anonymoushn 7y agoOh, this sounds quite pleasant. I'll have a look at the fork.
- leafo 7y agoDisclaimer: I'm the author of MoonScript > Yes, the class stuff in MS is plain wrong There's nothing wrong about it, I'm sorry you don't like it! I'm happy that you have your own ideas but to go around saying it's wrong isn't very cool. The system was very intentionally designed. Now that's it's been 9 years and I've written 100s of thousands of lines of MoonScript, the class has proved to be very reliable. It compiles to simple concepts that are easy to reason about when working with both large and small code bases. > The thing is, the prototypal, copy-on-write nature of Lua object orientation This line is confusing to me. There is nothing about lua that is fundamentally copy-on-write. That would have to be a choice the developer makes, but it would be hard to enforce with language primitives unless you're hiding data within meta-tables I think you're getting hung up on details that have nothing to do with MoonScript: if you want a different language then use a different language. Don't go around saying it's wrong because it's not the language you want.
- klibertp 7y agoNo way, that's too soon! I only recently started working on a MoonScript fork[1][2], I'm not ready for HN! ;) My use case is integration with Awesome WM, and I hope to bring MS up to modern standards (whatever they happen to be) in the process. The current MoonScript is in a really tight spot: the aging codebase doesn't get updated, there's no one leading the development, and the community has like 20 members tops. We need people! For both developing the language, discussing its design, and testing the changes. Feel free to drop by and say hi on Discord: https://discord.gg/Y75ZXrD https://discord.gg/Y75ZXrD Also, there's another effort aiming to modernize MS: a compiler written in C++: https://github.com/pigpigyyy/MoonPlus/ https://github.com/pigpigyyy/MoonPlus/ - it's new, but it already implements all of the MoonScript language - definitely worth taking a look at. [1] It started when I tried to add some FP conveniences to MS: https://github.com/leafo/moonscript/issues/407 https://github.com/leafo/moonscript/issues/407 [2] https://github.com/piotrklibert/AwesomeScript https://github.com/piotrklibert/AwesomeScript - nothing interesting yet, just a few ideas in the issues
- leafo 7y agoThanks for your enthusiasm, but I just wanted to clarify that I'm still leading the development of the project. I'm happy to see other people's ideas about how the language could be different, but I'm going to be very conservative about any accepted changes. I have a lot of code running in production in MoonScript that I have no plans to rewrite, so I have no plans to make breaking changes to the language. I feel it has reached a level of stability with the syntax that I'm mostly happy with. I encourage you to try out other stuff with your fork though. Hope that explains. For others, the discord linked above is the official one, so feel free to stop by.
- blargmaster33 7y ago"Significant whitespace" EPIC FAILURE!!!!!!
- aeosynth 7y agohttps://github.com/bakpakin/Fennel https://github.com/bakpakin/Fennel > Fennel is a lisp that compiles to Lua. It aims to be easy to use, expressive, and has almost zero overhead compared to handwritten Lua.
- iLemming 7y agoFennel rocks. So clean, so structured, so concise.
- pansa2 7y agoAs an embeddable language, does MoonScript’s significant indentation cause any problems? I imagine it could be difficult to include MoonScript code inline with C code while preserving the indentation. Is that so? Or is inline MoonScript code within C files not common?
- earenndil 7y agoI don't believe it's common to embed application scripting code within c source files, no.
- leafo 7y agoMy strategy is typically store MoonScript in separate files, then have build process that generates Lua and bundles that inside of whatever else. I wouldn't typically put it in a C file, but I might have the build system generate a hex encoded string as a header file. (This is actually how I build the MoonScript source into a single exe for Windows builds) I recommend doing the MoonScript compile time at program build time to avoid any unnecessary compilation during runtime.
- pansa2 7y agoThanks. I wonder if this would be any different if the VM executed MoonScript code directly, rather than first requiring translation to Lua. I’ve been thinking about the syntax of an embeddable language myself, and have ruled out significant indentation because of the difficulty of writing such code inline inside C files. If that’s not a common use case, maybe I should reconsider...
- leafo 7y agoThere is no MoonScript VM, if you use the "execute moonscript" function provided by the moonscript library it internally compiles the moon code to lua, loads the lua code, then runs the lua code. This means that MoonScript compiled ahead of time will have the same exact result as running it on the fly.
- xena 7y agoI really like MoonScript, it's a shame it's such a dead language.
- srean 7y agoCreator of Moonscript and Lapis [0] Leafo [ https://news.ycombinator.com/user?id=leafo https://news.ycombinator.com/user?id=leafo ] hangs out here from time to time [0] https://leafo.net/lapis/ https://leafo.net/lapis/
- kumarvvr 7y agoI am waiting for the day a subset of python is available in place of js in the browser. That is a language I wouldnt mind to work with on both server and client.
- beagle3 7y agoBrython, Transcrypt, RapydScript, Skulpt and PyPyJS provide various tradeoffs between compatibility and speed. Nim does server and client as well (compile down to C or JS serverside, JS clientside), and has Python inspired syntax and standard library. GWT gives you that for Java; Emscripten and recently WASM gives it to you with basically anything gcc can compile and then some. There is no need to wait.
- lwb 7y agoThe guy behind this language is Leaf, who also runs the indie gaming site http://itch.io http://itch.io. His twitter account is https://twitter.com/moonscript https://twitter.com/moonscript. Really cool guy and he often adds stuff to Itch after people request it on Twitter. Moonscript is what enables him and one other person to run one of the biggest indie sites on the web. (Small potatoes compared to Steam/Epic/Blizzard, but still much more impressive than that you might expect out of a two person team.)
- dang 7y agoLast big thread was in 2017: https://news.ycombinator.com/item?id=14441492 https://news.ycombinator.com/item?id=14441492 2012 https://news.ycombinator.com/item?id=4741331 https://news.ycombinator.com/item?id=4741331 2011 https://news.ycombinator.com/item?id=2871748 https://news.ycombinator.com/item?id=2871748 A bit more from 2011: https://news.ycombinator.com/item?id=3342912 https://news.ycombinator.com/item?id=3342912 Threads about the related web framework: 2019 https://news.ycombinator.com/item?id=19011356 https://news.ycombinator.com/item?id=19011356 2014 https://news.ycombinator.com/item?id=7744777 https://news.ycombinator.com/item?id=7744777 2013 Show HN: https://news.ycombinator.com/item?id=5602917 https://news.ycombinator.com/item?id=5602917
- lenkite 7y agoIf you like LISP and Clojure, you will like Fennel https://fennel-lang.org/ https://fennel-lang.org/ which also compiles to Lua
- leafo 7y agoHey all, thanks to whoever posted this. I'm the creator of MoonScript. I code in MoonScript daily, it's an integral part of many of my projects, including the company I run. It's something I launched a very long time ago, it's been featured on HN quite a few times now! I feel a little bad for threads like this: if you look at the github or the website, it hasn't seen any significant updates in quite some time. The reality is, though, it's reached a level of stability where I don't need to worry about it and I can work on using it to build other things. Although I have many ideas to fundamentally change it, introduce new operators, paradigms, etc., at the end of the day I value more that is has stayed pretty consistent. I have 100s of thousands of lines of MoonScript running in production environments. I'm more interested in refining the tooling & squashing bugs. I'm considering just bumping the version to 1.0 so people don't get confused about the viability of using it. If it's something you think fits your needs then go for it. I will continue to support it indefinitely because of how integrated it is into many of my projects. Tell me if you have any questions, thanks!
- fit2rule 7y agoThanks for your hard work leafo! As a huge fan of Lua I'm always bumping into your contributions to the language and tools .. Do you have some place where you organise your thoughts and make plans for Moonscripts' future?
- leafo 7y agoNot really, all of my time is going into my company so I'm not really thinking about big picture stuff with MoonScript. Some things I would like to eventually finish though: * JavaScript output backend https://github.com/leafo/moonscript-javascript-compiler https://github.com/leafo/moonscript-javascript-compiler * Replacing the AST transfomer with something written in tableshape: https://github.com/leafo/tableshape https://github.com/leafo/tableshape * Experimenting with writing an lpeg alternative that works more like a parser generator, experimented here https://github.com/leafo/moonparse https://github.com/leafo/moonparse * Formalizing the syntax transformation pipeline (this would be how things like macros could be implemented) If you have ideas feel free to open issues on the github. I may not be able to reply immediately but at least they are written down somewhere. Thanks