js2lua

Javascript to Lua translator

  • 所有者: wizzard0/js2lua
  • 平台:
  • 許可證:
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

# Javascript to Lua translator

Hey, I heard Javascript was made in 10 days!

So... this is an experiment with making a full-blown Javascript to Lua translator, preserving semantics and so on.

It's a single-pass transpiler that directly generates Lua code from the Esprima AST, without any kind of IR.
Quick-and-dirty, cutting corners, etc etc - don't expect much of this code :)
For example, each ternary expression (?:) generates 4 function calls and a closure - too lazy to implement anything more clever :)

Runs on vanilla LuaJIT, without any C modules or hacking the VM (e.g. Tessel runs on Lua, too, but on heavily modified runtime, which I didnt like)

Oh, and it probably can't bootstrap itself right now. Anyone willing to make it self-hosting? That would be cool :)

Results on ES5 test suite in 10 days:
Passed: 3659 Failed: 7753 Cannot Translate: 138 Skipped: 175 Total: 11725 Time: 1479.842

UPDATE: For more complete variants, see https://github.com/PaulBernier/castl. Also, https://github.com/Etiene/js2lua

Requirements and usage

Uses LuaJIT, esprima, lua-date, lpeglj, ta-regex, ast-hoist, esutils, escodegen

Tested under LuaJIT 2.1+ and node 0.10+.

Assumes LuaJIT binary at \bin\luajit\luajit

To run something: node run.js something.js. After translation, you can also use luajit something.lua to run translated code directly.

To run tests: node test\test.js test\sometestname.js. It compares STDOUT of JS and Lua versions to decide if the test passed.

To run entire ES5 test suite: node test\test.js test\es5\**\*.js (WARNING: Full suite takes over 20 minutes on fast, SSD-equipped machine!)
Some tests are blacklisted (grep for LUA_SKIP) because they cause infinite loop or do something similarly bad, they're marked as "skipped".

License: MIT

(c) 2015 Oleksandr Nikitin oleksandr@tvori.info

主要指標

概覽
名稱與所有者wizzard0/js2lua
主編程語言JavaScript
編程語言Lua (語言數: 4)
平台
許可證
所有者活动
創建於2015-01-22 10:04:36
推送於2018-02-20 08:53:10
最后一次提交2018-02-20 10:53:09
發布數0
用户参与
星數206
關注者數19
派生數17
提交數264
已啟用問題?
問題數5
打開的問題數5
拉請求數0
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?