7 ms·
I was thinking a while back, how nice it would be if lua was the scripting language in the browser instead of javascript. There are some projects to compile lua
by hackthemack 1y ago
I was thinking a while back, how nice it would be if lua was the scripting language in the browser instead of javascript. There are some projects to compile lua to wasm and have it run in the browser...
https://pluto-lang.org/web/#env=lua%3A5.4.6&code=if%20_PVERSION%20then%0A%09--%20Pluto%0A%09print(%22Hello%20from%20%22.._PVERSION)%0Aelse%0A%09--%20Lua%0A%09print(%22Hello%20from%20%22.._VERSION)%0Aend https://pluto-lang.org/web/#env=lua%3A5.4.6&code=if%20_PVERS...
But interoperability with the DOM is the missing key.
Still, if lua was used instead of javascript, I could see myself saying... man, I wonder what browser development would be like if we replaced lua with x.
- strenholme 1y agoThere’s also a Javascript implementation of Lua which allows one to run Lua in a browser: https://github.com/fengari-lua/fengari-web https://github.com/fengari-lua/fengari-web I don’t know if this can access the DOM in Lua, but considering that Fengari is in Javascript, adding a _DOM global variable should not be too hard (if it hasn’t already been done).
- bawolff 1y agoFengari lets you access the DOM. Its pretty cool.
- shakna 1y agoNo need for _DOM. local js = require "js" local window = js.global local document = window.document window:addEventListener("load", function() local el = document:getElementById("main") el:addEventListener("click", function(evt) js.console:log(evt.target) end document.body:appendChild(el) end
- james2doyle 1y agoThere is also nelua (https://nelua.io/ https://nelua.io/) which can use WASM to compile allow its usage in the browser: https://github.com/edubart/nelua-game2048/ https://github.com/edubart/nelua-game2048/
- realharo 1y agoWhat specifically do you think would be better? Lua shares many of JS's quirks (like the relationship between arrays and non-array objects, the behavior of undefined for non-existent object properties, metatables are somewhat similar to JS prototypes, etc.) and adds a bunch more (lack of continue statement, 1-indexing, cannot have nil values in tables). I can see people liking or disliking Lua and JS both, depending on taste, but it's hard to see someone liking one and disliking the other.
- mjmas 1y agoLua has goto instead of continue. Lua's metatables also cover a fair bit more ground than JS. For example, indexing, math operations (including bitwise), comparisons and equality can be overriden.
- TheCycoONE 1y agoI held a similar opinion several years ago. The main thing is that lua has less magic than js largely because it's been allowed to break compatibility. My main example is self in lua which is just the first argument of a function with some syntactic sugar vs this in javascript which especially before 'bind' often tripped people up. The coercion rules are also simpler largely by virtue of making 0 true.
- hackthemack 1y agoI agree mostly in that Lua and Javascript are both similar, and like I said in my post above, I could see myself saying the exact opposite if Lua had been included in the browser. The things I do not like about Javascript can easily be shot down in an argument. Some of it was having to work with Javascript (and it's evil cousin JScript) in the 90s and early 00s. The type coercion and in the early days people used '=='. I think === did not even appear until ie6? [] == ![] // true The lack of a lot of easy helper functions in the standard lib. That now are provided by people writing a bunch of stuff in the npm ecosystem. The npm ecosystem itself. Lack of security. Lack of... curation? (Also, all this would have probably happened anyway if Lua was in the browser) I also think javascripts long history has created a legacy of different paradigms variable declaration var, let, const function declaration function f1() {} const f2 = function() {}; const f3 = () => {}; const obj = { f4() {} }; There is a lot of stuff like this in javascript. I could probably make a blog post about it. But the above gives the general idea of my complaints.
- pansa2 1y agoIIRC Brendan Eich has talked about this - if he’d adopted Lua in 1995 instead of creating JavaScript, it wouldn’t have been Lua 5.x but Lua 2.x. Lua has improved substantially from version to version because it’s been able to break compatibility. That wouldn’t be possible in the browser, so today we’d still be stuck using (an augmented version of) the outdated Lua 2.x.
- strenholme 1y agoYes, he did: https://web.archive.org/web/20191024193930/https://twitter.com/BrendanEich/status/1187453118553837573 https://web.archive.org/web/20191024193930/https://twitter.c... “Lua in 1995 was very different, no coros e.g., and no one would be happy if it flash-froze and then slow-forked on a different path from Lua's. See https://news.ycombinator.com/item?id=1905155 https://news.ycombinator.com/item?id=1905155 and yes, wasm is the right long-term plan. In 1995 it was supposed to be Java, but that didn't pan out!”
- soapdog 1y agoFengari has DOM interop. http://fengari.io/ http://fengari.io/ It is a Lua reimplementation in JS.