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.
我需要找到一个好的Lua到JavaScript转换器; luaforj.org上的lua2js已经过时(大约3年左右,看起来它在Lua 5.1上不起作用)我还没有在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.
有没有人有任何其他转换器的经验?它应该适用于Lua 5.1,最好是基于.NET的,但.NET不是必需的。一个javascript lua解释器也可以工作。
9 个解决方案
#1
9
A new challenger appears: Lua.js https://github.com/mherkender/lua.js
一个新的挑战者出现:Lua.js https://github.com/mherkender/lua.js
For some awesome demos proving its maturity, see https://github.com/ghoulsblade/love-webplayer
对于一些证明其成熟度的精彩演示,请参阅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.
Lua.js的工作原理是将Lua代码直接转换为ECMAscript(包括JavaScript,ActionScript),这使得它比尝试在JavaScript中实现Lua VM的解决方案具有重要的速度优势。
#2
8
This is a recurrent question on the Lua list, i guess because of the superficial similarity of the two languages.
这是一个关于Lua列表的反复出现的问题,我猜是因为两种语言的表面相似性。
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.
不幸的是,有许多重要的差异并不那么明显。使其工作需要一个针对JS而不是Lua的字节码的完整编译器,或者需要在JavaScript中重写Lua VM。
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).
我不知道Lua2js的最初目标;但如果它只是一个有限的“翻译者”,那么编写想要翻译的Lua代码就会否认关于Lua的大部分(全部?)。例如,我不认为你可以使用函数作为表键,因为在JavaScript中键只是字符串(和数字?我不确定)。
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.
.NET选择更合理,可以通过更改现有编译器来发出CLR字节码而不是标准Lua字节码。即使CLR是针对其他类型的语言而设计和优化的,它也足够通用,可以很好地运行。主要障碍是图书馆的可用性。
Another option I just found is this paper by Roberto Ierusalmschy and Fabio Mascarenhas, where they explore translating LuaVM bytecode into CLR bytecode.
我刚刚发现的另一个选项是Roberto Ierusalmschy和Fabio Mascarenhas撰写的这篇论文,他们探索将LuaVM字节码转换为CLR字节码。
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.
正如学术论文中通常的那样,没有迹象表明它的编写日期,所以我不知道它是否是新的,革命的或旧的和被遗忘的。
#3
4
Emscripten contains the Lua interpreter converted to JavaScript. You can try it in your browser. However the size is 1.5MB.
Emscripten包含转换为JavaScript的Lua解释器。您可以在浏览器中试用它。但是大小是1.5MB。
#4
4
ljs has a working demo of a lua vm in javascript. Source code can even be compiled in the browser using a lua interpreter written in lua.
ljs在javascript中有一个lua vm的工作演示。源代码甚至可以使用lua编写的lua解释器在浏览器中编译。
#5
2
I've been using this implementation https://github.com/mherkender/lua.js that was mentioned in a previous answer. It does either offline and load-time parsing and I've found it very easy to use.
我一直在使用上一个答案中提到的这个实现https://github.com/mherkender/lua.js。它可以进行离线和加载时解析,我发现它非常易于使用。
My Lua scripts were calling through C-functions, and converting that C code to Javascript and getting it hooked up with lua.js has been pretty straightforward.
我的Lua脚本通过C函数进行调用,并将该C代码转换为Javascript并将其与lua.js连接起来非常简单。
#6
2
visit http://luajs.org to see my work.
访问http://luajs.org查看我的工作。
There are demos and benchmarks on site menu.
网站菜单上有演示和基准。
It's only 35.5K before compressing and 12.2K after compressing. It can access Javascript objects/arrays directly. It's updated nearly every day.
压缩前仅为35.5K,压缩后为12.2K。它可以直接访问Javascript对象/数组。它几乎每天都在更新。
It's faster than lua.vm.js. (Not so quick because of metatable implementation), and I keep optimizing it.
它比lua.vm.js快。 (因为metatable实现不那么快),我一直在优化它。
#7
0
Translation to javascript is interesting to allow for a javascript replacement on the browser-side. We could take a little type safety on the browser too. Targeting javascript as a platform is targeting one of the most pervasive platform, the browsers of the planet. GWT does java2js but I am not sure if I want to introduce GWT for only a few pages in an application. I have to think about it. For your function as a key in a table, there must be some magic to be done. Maybe just assign a unique name to each function at compilation and use that for your key. You can also add a prefix to all your keys for type checking and that is a nice start.
翻译为javascript很有趣,允许在浏览器端更换javascript。我们也可以在浏览器上采取一点类型的安全措施。将javascript定位为一个平台,目标是最普遍的平台之一,即地球上的浏览器。 GWT做java2js,但我不确定是否要在应用程序中仅为几页引入GWT。我得想想。为了将您的功能作为表中的键,必须要有一些魔力。也许只需在编译时为每个函数指定一个唯一的名称,并将其用于您的密钥。您还可以为所有键添加前缀以进行类型检查,这是一个不错的开始。
#8
0
One way of doing this could be using LuaSub and generating JavaScript instead of Lua output. This can be done, with reasonable effort (currently LuaSub does not do it).
一种方法是使用LuaSub并生成JavaScript而不是Lua输出。这可以通过合理的努力完成(目前LuaSub没有这样做)。
Places where JS cannot be bent to Lua's requirements could be discovered at compile time, and cause an error.
可以在编译时发现JS无法满足Lua要求的地方,并导致错误。
I am going to be doing a lot of JS+SVG in the future and if the JS side turns out a headache this may be a thing to try. If anyone else wants to have a go, please do so. The LuaSub source is there for you.
我将来会做很多JS + SVG,如果JS方面头疼,这可能是一件值得尝试的事情。如果有其他人想要去,请这样做。 LuaSub源代码适合您。
Originally, LuaSub was crafted as a syntax extender for Lua 5.1, to introduce ease-of-use concepts (s.a. increment, type check) without braking compatibility with standard Lua or needing to patch it. It is similar to MetaLua in this (which has become more commonplace, it seems).
最初,LuaSub是Lua 5.1的语法扩展器,它引入了易用的概念(增量,类型检查),没有与标准Lua的制动兼容性或需要修补它。它类似于MetaLua(似乎已经变得越来越普遍了)。
#9
0
I've written a partially complete Lua to ECMAscript static compiler.
我已经编写了一个部分完整的Lua到ECMAscript静态编译器。
https://github.com/mherkender/lua2js-experiment
It might not meet your needs, as the project is missing many key features and I'm not rushing to complete it because it's a dead-end. Read more in the README for details.
它可能无法满足您的需求,因为该项目缺少许多关键功能,我不急于完成它,因为它是一个死胡同。有关详细信息,请阅读README中的更多内容
Despite some of the concerns I've seen around the Internet, there's only a few Lua-specific features (like the *fenv functions, or most of the debug library) that Javascript can't really support. Others, like the file library, are limited by the features that the VM has access to.
尽管我在互联网上看到了一些问题,但只有少数特定于Lua的功能(如* fenv函数,或大多数调试库),Javascript无法真正支持。其他文件库(如文件库)受VM可访问的功能限制。
I also personally tried the Lua + Emscripten option, and while it's impressive, it is also very slow.
我个人也尝试过Lua + Emscripten选项,虽然它令人印象深刻,但它也很慢。
#1
9
A new challenger appears: Lua.js https://github.com/mherkender/lua.js
一个新的挑战者出现:Lua.js https://github.com/mherkender/lua.js
For some awesome demos proving its maturity, see https://github.com/ghoulsblade/love-webplayer
对于一些证明其成熟度的精彩演示,请参阅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.
Lua.js的工作原理是将Lua代码直接转换为ECMAscript(包括JavaScript,ActionScript),这使得它比尝试在JavaScript中实现Lua VM的解决方案具有重要的速度优势。
#2
8
This is a recurrent question on the Lua list, i guess because of the superficial similarity of the two languages.
这是一个关于Lua列表的反复出现的问题,我猜是因为两种语言的表面相似性。
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.
不幸的是,有许多重要的差异并不那么明显。使其工作需要一个针对JS而不是Lua的字节码的完整编译器,或者需要在JavaScript中重写Lua VM。
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).
我不知道Lua2js的最初目标;但如果它只是一个有限的“翻译者”,那么编写想要翻译的Lua代码就会否认关于Lua的大部分(全部?)。例如,我不认为你可以使用函数作为表键,因为在JavaScript中键只是字符串(和数字?我不确定)。
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.
.NET选择更合理,可以通过更改现有编译器来发出CLR字节码而不是标准Lua字节码。即使CLR是针对其他类型的语言而设计和优化的,它也足够通用,可以很好地运行。主要障碍是图书馆的可用性。
Another option I just found is this paper by Roberto Ierusalmschy and Fabio Mascarenhas, where they explore translating LuaVM bytecode into CLR bytecode.
我刚刚发现的另一个选项是Roberto Ierusalmschy和Fabio Mascarenhas撰写的这篇论文,他们探索将LuaVM字节码转换为CLR字节码。
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.
正如学术论文中通常的那样,没有迹象表明它的编写日期,所以我不知道它是否是新的,革命的或旧的和被遗忘的。
#3
4
Emscripten contains the Lua interpreter converted to JavaScript. You can try it in your browser. However the size is 1.5MB.
Emscripten包含转换为JavaScript的Lua解释器。您可以在浏览器中试用它。但是大小是1.5MB。
#4
4
ljs has a working demo of a lua vm in javascript. Source code can even be compiled in the browser using a lua interpreter written in lua.
ljs在javascript中有一个lua vm的工作演示。源代码甚至可以使用lua编写的lua解释器在浏览器中编译。
#5
2
I've been using this implementation https://github.com/mherkender/lua.js that was mentioned in a previous answer. It does either offline and load-time parsing and I've found it very easy to use.
我一直在使用上一个答案中提到的这个实现https://github.com/mherkender/lua.js。它可以进行离线和加载时解析,我发现它非常易于使用。
My Lua scripts were calling through C-functions, and converting that C code to Javascript and getting it hooked up with lua.js has been pretty straightforward.
我的Lua脚本通过C函数进行调用,并将该C代码转换为Javascript并将其与lua.js连接起来非常简单。
#6
2
visit http://luajs.org to see my work.
访问http://luajs.org查看我的工作。
There are demos and benchmarks on site menu.
网站菜单上有演示和基准。
It's only 35.5K before compressing and 12.2K after compressing. It can access Javascript objects/arrays directly. It's updated nearly every day.
压缩前仅为35.5K,压缩后为12.2K。它可以直接访问Javascript对象/数组。它几乎每天都在更新。
It's faster than lua.vm.js. (Not so quick because of metatable implementation), and I keep optimizing it.
它比lua.vm.js快。 (因为metatable实现不那么快),我一直在优化它。
#7
0
Translation to javascript is interesting to allow for a javascript replacement on the browser-side. We could take a little type safety on the browser too. Targeting javascript as a platform is targeting one of the most pervasive platform, the browsers of the planet. GWT does java2js but I am not sure if I want to introduce GWT for only a few pages in an application. I have to think about it. For your function as a key in a table, there must be some magic to be done. Maybe just assign a unique name to each function at compilation and use that for your key. You can also add a prefix to all your keys for type checking and that is a nice start.
翻译为javascript很有趣,允许在浏览器端更换javascript。我们也可以在浏览器上采取一点类型的安全措施。将javascript定位为一个平台,目标是最普遍的平台之一,即地球上的浏览器。 GWT做java2js,但我不确定是否要在应用程序中仅为几页引入GWT。我得想想。为了将您的功能作为表中的键,必须要有一些魔力。也许只需在编译时为每个函数指定一个唯一的名称,并将其用于您的密钥。您还可以为所有键添加前缀以进行类型检查,这是一个不错的开始。
#8
0
One way of doing this could be using LuaSub and generating JavaScript instead of Lua output. This can be done, with reasonable effort (currently LuaSub does not do it).
一种方法是使用LuaSub并生成JavaScript而不是Lua输出。这可以通过合理的努力完成(目前LuaSub没有这样做)。
Places where JS cannot be bent to Lua's requirements could be discovered at compile time, and cause an error.
可以在编译时发现JS无法满足Lua要求的地方,并导致错误。
I am going to be doing a lot of JS+SVG in the future and if the JS side turns out a headache this may be a thing to try. If anyone else wants to have a go, please do so. The LuaSub source is there for you.
我将来会做很多JS + SVG,如果JS方面头疼,这可能是一件值得尝试的事情。如果有其他人想要去,请这样做。 LuaSub源代码适合您。
Originally, LuaSub was crafted as a syntax extender for Lua 5.1, to introduce ease-of-use concepts (s.a. increment, type check) without braking compatibility with standard Lua or needing to patch it. It is similar to MetaLua in this (which has become more commonplace, it seems).
最初,LuaSub是Lua 5.1的语法扩展器,它引入了易用的概念(增量,类型检查),没有与标准Lua的制动兼容性或需要修补它。它类似于MetaLua(似乎已经变得越来越普遍了)。
#9
0
I've written a partially complete Lua to ECMAscript static compiler.
我已经编写了一个部分完整的Lua到ECMAscript静态编译器。
https://github.com/mherkender/lua2js-experiment
It might not meet your needs, as the project is missing many key features and I'm not rushing to complete it because it's a dead-end. Read more in the README for details.
它可能无法满足您的需求,因为该项目缺少许多关键功能,我不急于完成它,因为它是一个死胡同。有关详细信息,请阅读README中的更多内容
Despite some of the concerns I've seen around the Internet, there's only a few Lua-specific features (like the *fenv functions, or most of the debug library) that Javascript can't really support. Others, like the file library, are limited by the features that the VM has access to.
尽管我在互联网上看到了一些问题,但只有少数特定于Lua的功能(如* fenv函数,或大多数调试库),Javascript无法真正支持。其他文件库(如文件库)受VM可访问的功能限制。
I also personally tried the Lua + Emscripten option, and while it's impressive, it is also very slow.
我个人也尝试过Lua + Emscripten选项,虽然它令人印象深刻,但它也很慢。