5 ms·
Lua to Javascript translator
- daurnimator 14y agoWhat abilities does it have to interact with the DOM?
- jballanc 14y agoLua 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...
- mistercow 14y agoI disagree that Lua is better in every possible way. There are at least a couple of ways in which it is merely equal, yet where improvement would be possible.
- jballanc 14y agoPoint taken... "equal or better" in every possible way. :-)
- TazeTSchnitzel 14y agoPlease hack LuaJIT into WebKit. I was thinking of doing something even more crazy: hack Mono into WebKit!
- gruseom 14y agoI 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.
- azakai 14y ago> 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.
- bsg75 14y agoBut 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".
- azakai 14y agoI 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. ..?
- bsg75 14y ago> 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.
- bonch 14y agoLua won't complain about this: function example(x) print(X) end Because of the subtle bugs that can arise from Lua's undefined variable behavior, I prefer Squirrel: local a = {} a.x = 5 // Throws an exception a.x <- 5 // Assigns the value, creating the slot if needed Squirrel also supports JSON syntax for table creation.
- est 14y ago> Lua is a better language than Javascript in every possible way. How about unicode and regexp support?
- jballanc 14y agoSo regexp is easy: the Lua authors assert that their irregular-regular expressions (match library) cover the 80% use case for regular expressions while maintaining excellent performance and avoiding the hell that regexps can all too easily descend into. Based on some of the regexps that I've come across in my time...I'm inclined to agree with their decision. As for unicode, I also rather like their approach: we give you the low level tools, and you are free to implement whatever sort of encoding support you like on top of that. I used Ruby 1.8 when a string was just a bucket-o-bytes, and now I use Ruby 1.9 where every string MUST HAVE AN ENCODING OR ELSE! Based on my experience with both, I'd much rather not have encoding forced on me. That said, it would be nice to see a unicode implementation "blessed" by the core team (but the seem loath to "bless" any libraries).
- fshen 14y agoJavascript is an usable language, just need an open mind to learn it. Javascript is a simple language. Compile(translate) other language seems good. But complicated things.
- ufo 14y agoLua is simpler though
- leafo 14y agoThis is a cool project, but sadly it's not a complete Lua. It's missing two of Lua's most powerful features: A lot of the metatable functionality just won't work: http://www.lua.org/manual/5.1/manual.html#2.8 http://www.lua.org/manual/5.1/manual.html#2.8 Second, it's missing co-routines. Which is a way to suspend the execution of a piece of code. These features aren't possible in a compiler that simply translates from Lua to JS because JS doesn't have the ability to reproduce these concepts in its own constructs. You would have to output significantly different code to simulate these features. Without these you're just writing JavaScript in another dialect.
- bsg75 14y agoGiven this, what could be a legimate goal of this project? There are more than a few language X -> Y translators (not compilers), and I suspect they all miss some aspects of the source or target language.
- ufo 14y agoLooks like the only metatable stuff they don't dupport is weak references and garbage collection hooks (finalizers/destructors) Other then that t looks like the support most of the other stuff since table access and things like tha through intermediate functions such as lua_tableget and so on.
- RageKit 14y agoHum, i think everyone love javascript, but no one wants to actually write some ...
- RageKit 14y ago(thats what i can deduct from all these lib to convert whatever into js)
- freehunter 14y agoJavascript has the benefit of being able to easily run natively on the web. Lua is more complex to get running in a browser, as other languages are as well. Javascript has the disadvantage in that some people know and love and feel more comfortable in other languages. If you can convert from a language you love to a language that makes it easy to get into a browser... that's the dream.
- RageKit 14y agoYup, that's my case, i miss the easy workflow of other languages with "more feature". I miss native namespace and packaging, class, a code completion that works... etc
- snprbob86 14y agoVery 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"])
- haberman 14y agoVery 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.