
Moonshine – A lightweight Lua VM for the browser - keyle
http://moonshinejs.org/
======
MattJ100
This 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
Interesting, any useful resources you recommend for those interested in
learning how to write a VM in Javascript as a fun side project?

~~~
dubcanada
Don'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
Do 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
It's not really a VM then though, just a compiler.

EDIT: Maybe also a runtime.

------
fit2rule
Another good one - for those of us who love Lua (I Do!) is the MOAIFiddle
editor:

[http://getmoai.com/forums/moaifiddle-an-online-moai-
editor-a...](http://getmoai.com/forums/moaifiddle-an-online-moai-editor-and-
player-t2604/)

(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
I 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
I'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!

------
drivingmenuts
It 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.

~~~
ojii
There's [http://www.skulpt.org/for](http://www.skulpt.org/for) Python in the
browser.

~~~
CmonDev
That stuff uses JS. It would be nice to see a Python runtime in-browser with
no JS involved whatsoever.

~~~
chc
How 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?

~~~
CmonDev
"why would they" \- and that is the saddest part. We are locked-in now.

~~~
chc
I agree and used to agree very enthusiastically, but now I kind of understand
the browser makers' position. Like, I don't love having my favorite runtimes
locked out, but I also don't think having 15 virtual machines bundled with
every browser would be a great outcome either. We've already seen how in-
browser VMs turn out when they're not adequately maintained with Flash and
Java, and it isn't pretty and it leads to people's money getting stolen. So I
can't really blame the browser makers for not wanting to go down that road.

What we have now isn't the very best thing I can imagine, but I think it's an
OK compromise. We have a set of runtimes that implement a fairly consistent
Turing-complete set of instructions, so we can implement just about anything
we want and express it almost any way we want. And in the end, I think that's
the most important thing.

------
inm
A presentation given at the London Lua Group about it's development:
[https://skillsmatter.com/skillscasts/3820-developing-a-
lua-v...](https://skillsmatter.com/skillscasts/3820-developing-a-lua-vm-in-
javascript)

------
nnq
...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
_WHY? 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
Got some sample code or a link to it? I really like figuring out ways to
express existing code in a different style/pattern/language :)

------
Twisol
This 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.

~~~
fit2rule
Use luac locally to compile the bytecode, then include it in your deployment
to the server somewhere?

~~~
Twisol
The 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.

------
scotth
Has support for coroutines -- awesome!

~~~
k__
[citation needed]

~~~
scotth
The examples don't support deep linking, so here's how you get to the example:

Try It -> Examples -> Coroutines

~~~
k__
Ah. Thank you :)

------
EastLondonCoder
I work with moonshine, if you have any questions I would be happy to answer
them.

------
binocarlos
I'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
I 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.

~~~
rubiquity
Personally, 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
it compiles to an ast first

~~~
stcredzero
Years ago at Camp Smalltalk, Smalltalk VM implementers talked about compiling
everything to ASTs instead of bytecode.

------
rblstr
So weird to see this here

