Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any recent Lua to JavaScript converters or interpreters somewhere? [closed]

I need to find a good Lua to JavaScript converter; lua2js on luaforge.org is out of date (3 or so years old and looks like it doesn't work on Lua 5.1) and I haven't yet found anything on Google.

Does anyone have any experience with any other converters out there? It should work on Lua 5.1 and preferably be .NET based, but .NET is not a requirement. A javascript lua interpreter would work as well.

like image 796
Kevlar Avatar asked Oct 06 '08 21:10

Kevlar


People also ask

Does Lua use JavaScript?

Yes: The entire Lua 5.2. 4 codebase written in C is compiled to JavaScript here, including a full incremental GC and everything else. It fits in 170K of gzipped JavaScript.

How does a short comment in Lua start?

A comment in Lua is text that is completely ignored by the parser. Comments are generally added by the script writer to explain the code's intent. A short comment starts with a double hyphen ( -- ) anywhere outside a string and it extends to the end of the line.


2 Answers

A new challenger appears: Lua.js https://github.com/mherkender/lua.js

For some awesome demos proving its maturity, see https://github.com/ghoulsblade/love-webplayer

Lua.js works by converting Lua code directly to ECMAscript (including JavaScript, ActionScript), which gives it an important speed advantage over solutions which attempt to implement the Lua VM in JavaScript.

like image 195
Breton Avatar answered Oct 05 '22 07:10

Breton


This is a recurrent question on the Lua list, i guess because of the superficial similarity of the two languages.

Unfortunately, there are many important differences that are not so obvious. Making it work need either a full-blown compiler targeting JS instead of Lua's bytecode, or rewriting the Lua VM in JavaScript.

I don't know the original goals of Lua2js; but if it was simply a limited 'translator', then writing Lua code intended to be translated would deny most (all?) of the nice things about Lua. For instance, i don't think you could use a function as a table key, since in JavaScript the keys are only strings (and numbers? i'm not sure).

The .NET choice is more reasonable, it could be done changing the existing compiler to emit CLR bytecode instead of standard Lua bytecode. Even if CLR is designed and optimised for other kind of languages, it's definitely generic enough to run very well. The main hurdle would be the availability of libraries.

Another option I just found is this paper by Roberto Ierusalmschy and Fabio Mascarenhas, where they explore translating LuaVM bytecode into CLR bytecode.

As is usual on academic papers, there's no indication about the date when it was written, so i have no idea if it's new and revolutionary or old and forgotten.

like image 33
Javier Avatar answered Oct 05 '22 07:10

Javier