Live data from Hacker News

Lua to Javascript translator

github.com

11–20 of 30 posts

Re: Lua to Javascript translator

#11
post #3

Lua is a better language than Javascript in every possible way. I have half-a-mind to hack LuaJIT into Webkit, but I'm afraid that it may be futile at this point. The biggest shame in all of web development is the "type" attribute on the HTML "script" tag...

I have half-a-mind to hack LuaJIT into Webkit

I've been thinking for a while that Lua and especially LuaJIT are so good that there might exist a strategy to do an end run around vendors and get LuaJIT into browsers as (initially) a plug-in. It's possible that there's a killer app waiting to be written that could run well in LuaJIT (but not JS) and that this could drive installation of such a plug-in.

Re: Lua to Javascript translator

#12
Very cool project!

I know that this is somewhat off topic, but I'm thinking about this from the perspective of the ClojureScript compiler. The translation snippets in the Lua.js README make me really thankful for the design of Clojure. It's highly amenable to compilation. As a result ClojureScript is able to produce extremely well optimized output. For simple cases, the translation is no more unreadable than CoffeeScript. But even for complex cases, the performance is excellent because most forms compile to relatively plain & boring javascript.

    Lua      init(1, 2, 3)
    Lua.js   lua_call(lua_tableget(lua_script, "init"), [1, 2, 3]);
    CLJ      (init 1 2 3)
    CLJS     cljs.user.init.call(null, 1, 2, 3)

    Note that cljs.user is the default namespace in the ClojureScript REPL.

    Lua      local numActive = activeChars.count
    Lua.js   var numActive = lua_tableget(lua_tableget(lua_script, "activeChars"), "count")[0];
    CLJ      (let [num-active (.-count active-chars)])
    CLJS     var num_active__10317 = cljs.user.active_chars.count;

    Lua      local distFromCenter = get_distance({x=1, y=2})
    Lua.js   var distFromCenter = lua_call(lua_tableget(lua_script, "get_distance"), [lua_newtable(null, "x", 1, "y", 2)])[0];
    CLJ      (let [distance-from-center (get-distance {:x 1 :y 2})])
    CLJS     var distance_from_center__10322 = cljs.user.get_distance.call(null, cljs.core.ObjMap.fromObject(["\ufdd0'x", "\ufdd0'y"], {"\ufdd0'x":1, "\ufdd0'y":2}));

    Lua.js wins on that last example, but if you need more speed, you can get it. All of the JavaScript primitives are exposed with highly performant macros:

    CLJ      (aget (js-obj "x" 1 "y" 2) "x")
    CLJS     ({"x":1, "y":2}["x"])

Re: Lua to Javascript translator

#13
Very cool! Ignoring the relative strengths/weaknesses of the languages themselves, JavaScript's killer feature is that it is ubiquitous in web browsers and Lua's killer feature is that it has an extremely small and easy-to-embed implementation. With a project like this you could write code in Lua and get the best of both worlds.

When it comes to actually comparing the languages though, Lua is the language that you'd get if you had 10 years to refine JavaScript's design and throw out the cruft, IMO.

Re: Lua to Javascript translator

#14

Very cool! Ignoring the relative strengths/weaknesses of the languages themselves , JavaScript's killer feature is that it is ubiquitous in web browsers and Lua's killer feature is that it has an extremely small and easy-to-embed implementation. With a project like this you could write code in Lua and get the best of both worlds. When it comes to actually comparing the languages though, Lua is the language that you'd…

Don't you lose the compact advantage of Lua in the conversion?

Re: Lua to Javascript translator

#15
post #11
post #3

Lua is a better language than Javascript in every possible way. I have half-a-mind to hack LuaJIT into Webkit, but I'm afraid that it may be futile at this point. The biggest shame in all of web development is the "type" attribute on the HTML "script" tag...

I have half-a-mind to hack LuaJIT into Webkit I've been thinking for a while that Lua and especially LuaJIT are so good that there might exist a strategy to do an end run around vendors and get LuaJIT into browsers as (initially) a plug-in. It's possible that there's a killer app waiting to be written that could run well in LuaJIT (but not JS) and that this could drive installation of such a plug-in.

> I've been thinking for a while that Lua and especially LuaJIT are so good that there might exist a strategy to do an end run around vendors and get LuaJIT into browsers as (initially) a plug-in. It's possible that there's a killer app waiting to be written that could run well in LuaJIT (but not JS) and that this could drive installation of such a plug-in.

Please don't create yet another plugin. Plugins are bad for the web, they fragment it and if they end up de-facto standards that causes many problems too.

> It's possible that there's a killer app waiting to be written that could run well in LuaJIT (but not JS) and that this could drive installation of such a plug-in.

If you think there is something that needs improving in the web platform, contributing to that would be the best thing. If you have such a killer app that does not run well enough in current JS engines, you can contribute to one of the three open source JS engines to make it able to run your killer app.

Re: Lua to Javascript translator

#16
post #15
post #11

Earlier quoted context omitted.

I have half-a-mind to hack LuaJIT into Webkit I've been thinking for a while that Lua and especially LuaJIT are so good that there might exist a strategy to do an end run around vendors and get LuaJIT into browsers as (initially) a plug-in. It's possible that there's a killer app waiting to be written that could run well in LuaJIT (but not JS) and that this could drive installation of such a plug-in.

> I've been thinking for a while that Lua and especially LuaJIT are so good that there might exist a strategy to do an end run around vendors and get LuaJIT into browsers as (initially) a plug-in. It's possible that there's a killer app waiting to be written that could run well in LuaJIT (but not JS) and that this could drive installation of such a plug-in. Please don't create yet another plugin. Plugins are bad for…

But does not fragmentaion drive innovation (mutation -> evolution)?

If the only progress that occurs are incremental improvements to existing platforms, then the web is in "maintenance mode".

Re: Lua to Javascript translator

#17
post #16
post #15

Earlier quoted context omitted.

> I've been thinking for a while that Lua and especially LuaJIT are so good that there might exist a strategy to do an end run around vendors and get LuaJIT into browsers as (initially) a plug-in. It's possible that there's a killer app waiting to be written that could run well in LuaJIT (but not JS) and that this could drive installation of such a plug-in. Please don't create yet another plugin. Plugins are bad for…

But does not fragmentaion drive innovation (mutation -> evolution)? If the only progress that occurs are incremental improvements to existing platforms, then the web is in "maintenance mode".

I agree we need places where innovation can run wild, but also places where there are accepted standards.

The web is pretty much our only complete platform that is standards-based. Fragmenting it risks killing it. Remember when sites were "best viewed in IE" and people without Windows basically could not browse the web?

> If the only progress that occurs are incremental improvements to existing platforms, then the web is in "maintenance mode".

How about WebGL, 10x faster JS than just a few years ago, typed arrays, video and audio tags, WebRTC, etc. etc. ..?

Re: Lua to Javascript translator

#18
post #15
post #11

Earlier quoted context omitted.

I have half-a-mind to hack LuaJIT into Webkit I've been thinking for a while that Lua and especially LuaJIT are so good that there might exist a strategy to do an end run around vendors and get LuaJIT into browsers as (initially) a plug-in. It's possible that there's a killer app waiting to be written that could run well in LuaJIT (but not JS) and that this could drive installation of such a plug-in.

> I've been thinking for a while that Lua and especially LuaJIT are so good that there might exist a strategy to do an end run around vendors and get LuaJIT into browsers as (initially) a plug-in. It's possible that there's a killer app waiting to be written that could run well in LuaJIT (but not JS) and that this could drive installation of such a plug-in. Please don't create yet another plugin. Plugins are bad for…

[deleted]

Re: Lua to Javascript translator

#19
post #17
post #16

Earlier quoted context omitted.

But does not fragmentaion drive innovation (mutation -> evolution)? If the only progress that occurs are incremental improvements to existing platforms, then the web is in "maintenance mode".

I agree we need places where innovation can run wild, but also places where there are accepted standards. The web is pretty much our only complete platform that is standards-based. Fragmenting it risks killing it. Remember when sites were "best viewed in IE" and people without Windows basically could not browse the web? > If the only progress that occurs are incremental improvements to existing platforms, then the we…

> How about WebGL, 10x faster JS than just a few years ago, typed arrays, video and audio tags, WebRTC, etc. etc. ..?

I was not implying that innovation had ceased. On the contrary, I love seeing stuff like this appear. Even if doomed from the outset to not become standard or widespread, the potential from experimentation is what keeps things interesting.

Post reply on HN