6 ms·
Fengari: Lua for the Browser
- scardine 9y agoLua is one of the few popular programming languages originated from the South Hemisphere - other example is Elixir (not sure if it was also created here in Brazil, but I think Jose Valim is Brazilian).
- Willamin 9y agoWhile it's not as popular as Lua or Elixir yet, I believe Crystal (crystal-lang.org) will be "the next big thing" in a few years. It's also from the Southern Hemisphere.
- krylon 9y agoTL;DR - A Lua 5.3 VM written in Javascript. I like Lua very much, and in my mind, if the stars had been aligned just a little differently, it would now occupy the space inhabited by Javascript. I cannot help but wonder, tough: A Lua VM implemented in Javascript? Is the performance hit not enough to make this useless for anything beyond proof-of-concept-sites/apps? A Lua to Javascript compiler would have made sense. Given all the languages you can compile to Javascript these days, it would have made sense. And in terms of semantics, both languages are close enough that I think it would not be that big a problem. Still, it is an impressive piece of work. Implementing a bytecode VM a) in Javascript, b) running in the browser must make debugging rather ... interesting.
- agumonkey 9y agoI planned to extend dillo with lua. I so far I have patch with the includes and the lua interpreter init.. annnnd that's it. I know nothing about interfacing interpreter with the browser components (dom, etc) so I stopped.
- cypher543 9y agoDillo specifically avoids scripting, so I doubt the internals are well-suited to that sort of integration. You could try extending NetSurf[1], though. It uses Duktape[2] as its Javascript engine and its API is pretty similar to Lua's. 1: http://www.netsurf-browser.org/ http://www.netsurf-browser.org/ 2: http://duktape.org/ http://duktape.org/
- agumonkey 9y agoThanks, I should look how others did it. It's true that dillo never cared about scripting, I felt like plugin lua in would force a rewrite of every part..
- squarefoot 9y agoYou may find the Luakit browser interesting. https://luakit.github.io/ https://luakit.github.io/
- agumonkey 9y agoThanks, I looked at it, I wanted a crude web browser, not a modern html5/css3/js(6). The point was to make an extremely light, yet programmatic access to web data and almost static html. When I use dillo I don't miss much, maybe a few css fix here and there. What I feel is that I want some emacs-ish capabilities in it so I can do more with less. And I love the ridiculous resource consumption of dillo, 30 dillo tabs = half a chromium one; and without parsing js and fetching scripts .. network + rendering is hard to measure.
- flohofwoe 9y agoYou can just take the original Lua interpreter source code and compile that to asm.js or WebAssembly without changes. Loading dependencies from the web requires an asynchronous reimplementation of the "require" command though, but it's all quite trivial. The result is about 100 to 150 KByte compressed. The only downside (beside the added size) is that the Lua code is still running interpreted, not JITed. That's why I think that a combination of WebAssembly for performance critical code, and Typescript (compiled to Javascript) for the 'scripting part' makes more sense than WebAssembly+Lua, since this doesn't have those downside (no additional size overhead for the interpreter, and the JS will be JITed).
- sitkack 9y agoI have tested Lua compiled to asmjs and it is very very fast. A LuaJIT that targeted WASM would be phenomenal, but not strictly needed. Or maybe something like Terra [0] but targeted WASM. Either one would meet all of my perf needs. Lua really is the MLIR (mid-level intermediate representation) from the future. [0] http://terralang.org/ http://terralang.org/
- __s 9y agoI've been working on a hand written Lua interpreter in WASM (using Lua as a macro assembler, ofc). Long term I'd like to have it jit wasm code: https://github.com/serprex/luwa https://github.com/serprex/luwa Currently in the process of porting the parser & codegen that's implemented in Javascript to Lua so that I can have the implementation bootstrap itself. Plus the codegen was for a bytecode I came up with in JS but which has evolved quite a bit since getting everything in place to happen in WASM
- sitkack 9y agoThis is super cool. It looks like you are in the process of porting the .js to .lua? Wasm will exist in many more places than Js will. I think I would have started with many of the Lua on Js implementations and used zero Js. Have you seen http://stefan-marr.de/2015/10/jit-data-structures-fully-reflective-vms-and-meta-circular-meta-tracing/ http://stefan-marr.de/2015/10/jit-data-structures-fully-refl... Check out this paper, https://www.cs.purdue.edu/homes/rompf/papers/amin-draft2017a.pdf https://www.cs.purdue.edu/homes/rompf/papers/amin-draft2017a... Collapsing Towers of Interpreters
- nstat41 9y agoWould be wild if you could work FFI with webasm in here somehow
- vvanders 9y agoNo need to do that, you can use wasm to build lua[1], although the API definitely needs some clean up. This looks much nicer from a JS integration perspective. [1] https://github.com/vvanders/wasm_lua https://github.com/vvanders/wasm_lua
- chx 9y agoHail the light! Down with the tyranny of JavaScript! This is fantastic!
- giann 9y agoInteraction with JS with Fengari is as simple as "js.global:alert('hello')" with https://github.com/fengari-lua/fengari-interop https://github.com/fengari-lua/fengari-interop
- feelin_googley 9y agoI recall lua for the browser beginning in 2001. http://web.archive.org/web/20010428142032/http://links.sourceforge.net:80/links-lua/ http://web.archive.org/web/20010428142032/http://links.sourc... http://web.archive.org/web/20090227050803/http://article.gmane.org:80/gmane.comp.web.elinks/30 http://web.archive.org/web/20090227050803/http://article.gma... http://elinks.or.cz/documentation/html/manual.html-chunked/ch14.html http://elinks.or.cz/documentation/html/manual.html-chunked/c...
- marktangotango 9y agoThis is really cool, I'd love to write frontends in Lua. For side project backend development, I've been using Apache and mod_lua[1] (Openresty is Lua for nginx[2]) for a couple of years now. In particular Lua with Luajit is such a kick ass platform, I've always wondered why it hasn't gotten more attention than it has. There are at least two high quality event loop http servers written with it [3][4] and some quite mature web application frameworks [5][6]. Really seems like the Lua backend story is set to explode. [1] https://httpd.apache.org/docs/trunk/mod/mod_lua.html https://httpd.apache.org/docs/trunk/mod/mod_lua.html [2] https://openresty.org/en/ https://openresty.org/en/ [3] https://luvit.io/ https://luvit.io/ [4] https://github.com/daurnimator/lua-http https://github.com/daurnimator/lua-http [5] http://leafo.net/lapis/ http://leafo.net/lapis/ [6] http://sailorproject.org/ http://sailorproject.org/
- mmjaa 9y agoFront ends in Lua? Say no more: http://github.com/moai/moai-dev/
- chc4 9y agoLearning that itch.io is powered by Lua was pretty cool. There's a [write-up] about how they leveraged coroutines for async programming which is super nice to read. iirc, Cloudflare uses mod_lua for a lot of its packet filtering stuff because Luajit is basically magic. write-up: http://leafo.net/posts/itchio-and-coroutines.html http://leafo.net/posts/itchio-and-coroutines.html
- a_imho 9y agoI really like 'plain' Openresty and Lua and use it to power my backend. It is very straightforward and minimal. Nginx is always in the mix and using homogenous technology in the stack simplifies things even further. Also experimented with using it as a websockets server and worked quite pleasantly out of the box. There is a very nice collection of libraries with pretty much everything one can think of https://github.com/bungle/awesome-resty https://github.com/bungle/awesome-resty
- noahdesu 9y agoLinks to the slides and video presentations from the Lua workshop [0] last month, including one on Fengari [1]: [0]: https://www.lua.org/wshop17.html https://www.lua.org/wshop17.html [1]: https://www.youtube.com/watch?v=xrLIgmd8xik https://www.youtube.com/watch?v=xrLIgmd8xik
- giann 9y agoI'm the author of Fengari alongside Daurnimator. Please take a look at https://www.youtube.com/watch?v=xrLIgmd8xik https://www.youtube.com/watch?v=xrLIgmd8xik (slides: https://www.lua.org/wshop17/fengari.html https://www.lua.org/wshop17/fengari.html) for an introduction to it and an explanation as to why this approach is the only viable one to use Lua in the browser and interact with the DOM.