
The Lua VM, on the Web - vmorgulis
http://daurnimator.github.io/lua.vm.js/lua.vm.js.html
======
scrame
So, I understand that asm.js is a strict subset of JS that's made to run very
efficiently. I understand emscripten can transpile C to asm.js, so C programs
to run in a browser.

I guess what I don't understand is how the higher-level bindings work.
Something like the neo-geo emulators running in asm.js can read controllers
and output graphics. How much custom code is required going from system C to
browser JS. Is it closer to a 'gimme' if it targets GL and can just use WebGL?
Is there something like sdl.js? And if it has those external library
dependencies, does the whole dependency tree have to be compiled to asm.js?

More specifically, if the lua VM can be put into the browser, and interpret
lua code, then how much custom code would it take to make Love2D work?

Edit: Just re-reading this question I realized it'd most likely be like a
static build, so it would pull in the dependency source, and then most likely
something that would use the io/display stuff API, but with a browser back-
end. I've dug around a couple times trying to find a basic overview of that,
but to not much avail. I'd love any references though.

~~~
cygx
Emscripten[1] comes with SDL support (cf its test suite [2]). Not sure how
complete it is.

[1] [http://kripken.github.io/emscripten-
site/](http://kripken.github.io/emscripten-site/)

[2]
[https://github.com/kripken/emscripten/blob/master/tests/hell...](https://github.com/kripken/emscripten/blob/master/tests/hello_image_sdl.c)

~~~
vitovito
The original SDL support was a JavaScript implementation of just enough of 1.x
to get things compiling.

SDL2 cross-compiles to JavaScript properly and should be used by most things
now.

~~~
scrame
so emscripten provides the sdl binding? I was assuming it'd cover libc, but
does that mean it's part of the ecosystem or the compiler?

I feel like I'm just asking dumb toolchain questions because I'm missing
something fundamental about targeting an executable build to the browser.

~~~
corysama
I think this is what you are missing.

[https://kripken.github.io/emscripten-
site/docs/porting/conne...](https://kripken.github.io/emscripten-
site/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html)

------
s369610
I Ported the MOAI engine of Broken Age fame to html/emscripten, It runs full
lua along with a bunch of other libraries (libpng, freetype etc) You can see
it running here (and edit the code and run in browser)
[http://moaiforge.com/samples/sample-
browser/player/index.htm...](http://moaiforge.com/samples/sample-
browser/player/index.html#hello-moai)

~~~
Tanner
Hey, we interacted a little over 2 years ago when I was talking about a hand-
coded port of Love2D to the web using Moonshine. Eventually the dependencies
for Love did get to the point where I could do an emscripten port. Just wanted
you to know that your project and our little interaction has stuck with me.

The emscripten port of Love.js:
[https://github.com/TannerRogalsky/love.js](https://github.com/TannerRogalsky/love.js)

~~~
s369610
Wow, glad to see it come together! Love2d is so clean, it is great that it
works in browser now.

------
lopatin
This is really cool. I know Lua is a commonly embedded language for plugins
and stuff. So now that we can support Lua powered extensions for web apps, I'd
like to add to the list of naive questions here, coming from someone who's
never used the language. What benefits does Lua provide over other langs for
such a purpose? Is it the ecosystem of libraries that makes it unique in that
respect? Or the actual language lends itself better for user scripting over,
say, running JS code through JS-interpreter or just eval-ing validated JS code
directly.

~~~
john_reel
Lua is perfectly multiparadigm. Anyone who hasn’t tried it should.

~~~
sprobertson
I only recently realized how much lua I'm using day to day:

* nginx modules (proxying rules)

* Redis modules (special triggers)

* Machine learning with Torch

* Embedded systems (ESP8266)

------
nitemice
The future is coming!

[https://www.destroyallsoftware.com/talks/the-birth-and-
death...](https://www.destroyallsoftware.com/talks/the-birth-and-death-of-
javascript)

~~~
bogomipz
I have watched this talk on two occasions now. Gary Bernhardt is really a
great speaker. I am curious has anyone subscribed to the screencasts at:

[https://www.destroyallsoftware.com/screencasts](https://www.destroyallsoftware.com/screencasts)

It's a bit pricey at $29 dollars a month but if all of the content is as
interesting, entertaining and thought provoking as this talk I could see it
being worth the price. I would be curious to hear anyone's feedback.

------
marktangotango
So, a bit off topic, but is anyone using Lua for web application backends? For
example Lua with nginx or mod_lua for apache? I've used Lua with mod_lua, and
have been very happy with the result. There are actually a lot of libraries
available on luarocks.org, although not at the 'batteries included' level of
Python.

~~~
etiene
I use my own framework. It's MVC and it works on the top of nginx(openresty),
apache(mod_lua) and xavante (a pure Lua web server). It's called Sailor
[http://sailorproject.org](http://sailorproject.org)

I also wrote a blog post with a comparison of different frameworks:
[http://lua.space/webdev/the-best-lua-web-
frameworks](http://lua.space/webdev/the-best-lua-web-frameworks)

------
vmorgulis
Few running example: [http://mangelmaxime.github.io/Lua.vm.js-
Samples/pages/www/](http://mangelmaxime.github.io/Lua.vm.js-
Samples/pages/www/)

------
d33
I'm surprised nobody said it here - it would be even cooler with webassembly!
Imagine writing Lua code instead of JS...

EDIT: though now that I look at it, it's already possible:

[https://daurnimator.github.io/lua.vm.js/script_example.html](https://daurnimator.github.io/lua.vm.js/script_example.html)

~~~
daurnimator
webassembly gains lua.vm.js nothing: it's just a bytecode form of asm.js

The big thing lua.vm.js needs is weakrefs [https://github.com/tc39/proposal-
weakrefs](https://github.com/tc39/proposal-weakrefs)

------
etiene
This is another Lua VM worth taking a look:
[http://starlight.paulcuth.me.uk/](http://starlight.paulcuth.me.uk/)

I use both of them with Sailor, but I tend to prefer starlight recently

------
ww520
This is very cool. The Lua VM can run in Node.js backend in this case.

~~~
ufo
If you are in the server why not just run Lua directly?

------
qwertyuiop924
Now I want to see how the performance compares to that of Moonshine.

------
scardine
Lua and Elixir are among the few relevant contributions to the field coming
from Brazil.

