9 ms·
Moonshine – A lightweight Lua VM for the browser
- binocarlos 13y agoI'm loving how everything is moving to JS :) Can someone explain why I might want to use Lua in a browser over JS? Does it have a fundamental feature that JS does not have? Cool name btw!
- swah 13y agoI hate how everything is moving to JS :) I wish somehow there were multiple languages targetting a common bytecode.. but that won't happen for some reason I can't understand because I stopped in the middle of the dragon book.
- chrisdevereux 13y agoI don't think the dragon book will help unless the new edition has a section on how to organise a standards committee for your new language.
- rayiner 13y agohttp://www.jwz.org/doc/worse-is-better.html http://www.jwz.org/doc/worse-is-better.html
- rubiquity 13y agoPersonally, I feel that the biggest slap in the face to developers in the last decade is that V8 uses native code instead of byte code. In 10-20 years I hope we look back on Google's decision to do that and hate them for it.
- jlebrech 13y agoit compiles to an ast first
- stcredzero 13y agoYears ago at Camp Smalltalk, Smalltalk VM implementers talked about compiling everything to ASTs instead of bytecode.
- espadrine 13y agoI do understand why nobody would want to target Hydrogen directly, but here's a Hydrogen IR inspector tool: http://mrale.ph/irhydra/1/#ir http://mrale.ph/irhydra/1/#ir
- CmonDev 13y ago"In 10-20 years" - let's hope ES6 is released before that.
- herokusaki 13y agoHonest question: why is it a slap in the face to developers?
- rubiquity 13y agoBecause we could then have a virtual machine that we could send bytecode to, instead of having all of these languages that compile to JavaScript, which eventually gets compiled to native code by V8.
- ben0x539 13y agoI think the point of contention is that there isn't really such a thing as a completely language-neutral bytecode, so nobody can agree on whose language-specific-js-replacement vm to ship.
- stormbrew 13y agoIf JS ever gets finalizers we could probably consider the total feature set JS has at that point sufficient for the implementation of most other dynamic languages without resorting to writing a VM in js or using asm.js to embed a full C runtime using arraymaps for a heap. At that point we'd probably see some subset of JS devolve to a bytecode, I'll bet.
- Yorrrick 13y agoIt's simple. "Bytecode" is just a kind if encoding. The only thing it does is make programs marginally smaller and marginally quicker to decode. It's not enough to justify enormous switching costs. Let's talk about what functionality this new thing should have. That's where the high-value opportunities are. But, it's also where there's no easy consensus.
- stcredzero 13y agoHence, there are high value opportunities in JS as a compilation target/runtime platform.
- duaneb 13y agoYou know what's a perfect, concise byte code? An ast-laden ASCII blob. What's the byte code for a byte array again? Oh there isn't one.... What's the byte code for a compare and swap? Shit....
- rational_indian 13y agoIt has 1 based indices, oh joy!
- stcredzero 13y agoYes, but you can code with 0 based indices just fine, when you need it. I know, because I've done it.
- plorkyeran 13y agoCoroutines, and Lua's metatables are more powerful than what can be done in ES5 (ES6 closes the gap a bit, and generators are equivalent to coroutines). Lua is pretty much JS done right, which actually makes it a poor choice for something like this IMO. A program written in Lua is not going to be fundamentally different from the same program written in JS, and the problems introduced by using this (worse debugging experience etc.) are very likely to outweigh the benefits of avoiding JS's warts.
- stcredzero 13y ago(worse debugging experience etc.) How do you know? Maybe try this first? Apparently, there is a in-browser debugger you can activate just by including two files. This is theoretically a first-class debugger that doesn't even need source maps. http://moonshinejs.org/how-to/debug-locally/ http://moonshinejs.org/how-to/debug-locally/ Were you assuming that Moonshine is a compiler targeting Javascript? It's actually a Lua bytecode VM.
- anonymoushn 13y agoGenerators are equivalent to corourintes only as long as every single function you write is a generator and every single function call (to one of your own funcitons, anyway) is actually delegating to another generator. You can use a trampoline to make this less painful, but then you don't get to see your "real" call stack in the debugger...
- Tanner 13y agoFrom my cursory evaluation, the debugging support is actually better than vanilla Lua. The only point of friction I can see if that you have to "compile" something that is normally interpreted.
- paulcuth 13y agoThis is true. However the distiller can --watch a directory and do this step for you in the background. For more info: $ moonshine help distil
- MattJ100 13y agoThis is great to see! It's important to note that this isn't just yet another "X compiled to Y using Z", but a VM written from scratch natively in Javascript. The result is a much smaller size, it's more understandable, hackable, extensible - all things that Lua's standard C implementation is great for. It's likely also easier to optimise this way. I began on a similar project some years back, but as many spare-time projects go, never finished it: http://code.matthewwild.co.uk/ljs http://code.matthewwild.co.uk/ljs
- j-b 13y agoInteresting, any useful resources you recommend for those interested in learning how to write a VM in Javascript as a fun side project?
- dubcanada 13y agoDon't write it in JS :) No but seriously, if you want to write a VM in Javascript, I would suggest learning how to write a VM in a language more suited to writing a VM in. Maybe C or C++ then writing one in Javascript.
- stcredzero 13y agoDo what you want. The nice thing about writing a managed language with GC in a managed language with GC, is that you don't have to write the GC. (Or the JIT, if you do it right.)
- yoklov 13y agoIt's not really a VM then though, just a compiler. EDIT: Maybe also a runtime.
- drivingmenuts 13y agoIt would be nice to see other languages available as real languages, not compiled down to Javascript. I love me some javascript, but it would be nice to work in Python, in the browser.
- neovive 13y agoIt would be nice to see Lua embedded as an option within browsers, since it's such a small language and already designed to be embedded.
- fit2rule 13y agoLua is indeed, embeddable anywhere. Its such an elegant little VM, and you can just put it wherever you want. It is some sort of mad invasive engine .. you use it once, and from that point on you pretty much can't see anywhere else you wouldn't just use it, of course .. if you had to, or wanted to, and .. the more you use the Lua VM stack, the more you just want to keep doing things that way. It is neat.
- ojii 13y agoThere's http://www.skulpt.org/for http://www.skulpt.org/for Python in the browser.
- Cederfjard 13y agoYou happened to append for to the url. As a convenience: http://www.skulpt.org http://www.skulpt.org
- CmonDev 13y agoThat stuff uses JS. It would be nice to see a Python runtime in-browser with no JS involved whatsoever.
- chc 13y agoHow do you envision this happening? Either the runtime would have to be written in JS or you'd have to get all the browser implementers to adopt your virtual machine — which, I mean, why would they?
- inm 13y agoA presentation given at the London Lua Group about it's development: https://skillsmatter.com/skillscasts/3820-developing-a-lua-vm-in-javascript https://skillsmatter.com/skillscasts/3820-developing-a-lua-v...
- rblstr 13y agoSo weird to see this here
- scotth 13y agoHas support for coroutines -- awesome!
- uaygsfdbzf 13y agoI would absolutely love to be able to use Lua for web development, I wonder how this performs though...
- nnq 13y ago...I know it's the fashion to write compile-to-js languages and js-VMs for other languages, but I really have to ask: WHY? I mean, Lua is a dynamic language with first class functions just like Javascript is, no big difference here. I understand clojurescript, parenscript and haskell to js compilers, because these languages are really different from javascript, so they offer you a very different way of working and different tradeoffs (Clojure, CL, Haskell offer you the ability to choose a programming style that is just not possible in Javascript). Maybe even Opal or Amber - rubyan/smalltalkian oop semantics really are very different from Javascript's and you end up using very different design patterns. And I understand the wish to have static typing for large projects/teams, ergo TypeScript or Dart. But I really don't understant why would anyone go through such pain (by pain I mean not writing the transcompiler/vm, this is the fun part, I know, but debugging it, maintaining it and debugging the code you use it on), to use a language so similar to Javascript, like Lua or Python, instead of using just plain Javascript and making some minor effort to 'use strict', avoid some dark corners and get used to living with a little less syntactic sugar?
- stcredzero 13y agoWHY? I mean, Lua is a dynamic language with first class functions just like Javascript is, no big difference here. You can use objects as keys in Lua. This makes a lot of code in Lua a pain to port to JavaScript. I have Lua code I would like to port to JavaScript that this applies to.
- nnq 13y agoGot some sample code or a link to it? I really like figuring out ways to express existing code in a different style/pattern/language :)
- Excavator 13y agoMap¹ might've been an option, excepting no support in Safari and IE < 11. Although I dunno about the performance hit, if any. ¹ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- 13y ago
- fit2rule 13y agoAnother good one - for those of us who love Lua (I Do!) is the MOAIFiddle editor: http://getmoai.com/forums/moaifiddle-an-online-moai-editor-and-player-t2604/ http://getmoai.com/forums/moaifiddle-an-online-moai-editor-a... (Edit: some direct links to already-working examples: http://moaifiddle.com/Q09BJWGMW6 http://moaifiddle.com/Q09BJWGMW6 and http://moaifiddle.com/262FBR1ZR8 http://moaifiddle.com/262FBR1ZR8 and http://moaifiddle.com/262FBR1ZR8/2 http://moaifiddle.com/262FBR1ZR8/2) This is a full-blown (web-based) development environment for the MOAI Game toolkit, which just happens to be able to deploy to not only Android, iOS, Windows, Linux, OSX hosts .. but also - as demonstrated - to html5+js hosts. So, if you've ever wanted to check out MOAI but have been put off by the need to build your own host for the OS of your choice, you can just use moaifiddle to get your project done, see the results directly in-browser, and prepare your app before even having to download the MOAI SDK. Sweet! (More details about the cross-platform game toolkit, MOAI, are available here: http://getmoai.com/ http://getmoai.com/)
- woogley 13y agoI love Lua too but I've tried to get into Moai several times and I just can't seem to stomach it. Maybe I let Corona spoil me. The documentation is especially off-putting: http://getmoai.com/docs/ http://getmoai.com/docs/
- fit2rule 13y agoI've been working with MOAI for 3 years now, so I guess I'm quite biased - but I find it awesome. Yes, the Docs - well these are generated docs, courtesy of doxygen. You really need to start at the wiki, and then work your way through all the samples in $MOAI_ROOT/samples/ http://getmoai.com/wiki/index.php?title=Main_Page http://getmoai.com/wiki/index.php?title=Main_Page And of course the tutorials and other refs from the github: https://github.com/moai/moai-dev/ https://github.com/moai/moai-dev/ MOAI does take some patience - but on the other side of that effort, is a fantastic framework that makes game development easy and fun. There's something just so elegant about it!
- speeder 13y agoMoai is just... terrible. I work with Lua-based engines on my startup, and right now the "winner" is Gideros. Corona is also good (But has several issues that made me use Gideros for the current project, but all currently done projects were made with Corona). Corona is going for HTML5, I hope Gideros can do something like that soon too.
- EastLondonCoder 13y agoI work with moonshine, if you have any questions I would be happy to answer them.
- Twisol 13y agoThis would be even more amazing if there was no dependency on `luac` to compile to Lua bytecode. I'm developing a web application with user-scriptable features, and I'd love to use Lua (to provide a better user experience for my non-webdev audience), but the dependency on a server-side compilation step is a problem for my use-cases.
- paulcuth 13y agoThere is a Moonshine extension[1] that uses Yueliang[2] to compile offline in the browser, but it's quite slow. I'm hoping to speed it up a bit in the near future, with the futures I'm working on now. [1] https://github.com/gamesys/moonshine/tree/master/extensions/luac https://github.com/gamesys/moonshine/tree/master/extensions/... [2] http://yueliang.luaforge.net/ http://yueliang.luaforge.net/
- fit2rule 13y agoUse luac locally to compile the bytecode, then include it in your deployment to the server somewhere?
- Twisol 13y agoThe app front-end has user-scriptable features - I should have been more specific. My app has no back-end, and it is unacceptable to set up a back-end for the sole purpose of running luac on user scripts.