*** Note: This is work in progress. It's still early days and is not really usable yet. ***
Hamlet is a JavaScript to Lua translator and runtime. It is still in development and is probably not capable of running your JavaScripts. Yet.
This project aims to:
- create an ES5.1-compliant JavaScript runtime written in Lua.
- create an embeddable JavaScript runtime.
- create a minimal JavaScript runtime, with ability to pick 'n' mix features.
- make packages in the NPM registry available to use in Lua runtimes.
Currently you will need Node and Gulp installed to build Hamlet. In theory, once Hamlet is complete, the parser and acorn.js dependency can be translated to Lua and Node will no longer be required.
You'll need Lua, LuaJIT and Node to run the tests, as the same script is benchmarked and compared in all three runtimes.
git clone git@github.com:paulcuth/hamlet.git
cd hamlet
npm install
gulp
This will build out/hamlet.lua
, compile the Sputnik conformance tests and run the latter in the former.
If you only wish to build Hamlet, use gulp build
instead.
You can use any of the following commands to run your JavaScript code:
lua out/hamlet.lua myscript.js
luajit out/hamlet.lua myscript.js
lua out/hamlet.lua -e "console.log('Hello world');"
luajit out/hamlet.lua -e "console.log('Hello world');"
You can also translate your JavaScript to Lua in advance and then run that in Hamlet:
node parser/parser.js myscript.js > myscript.lua
lua out/hamlet.lua myscript.lua
- Conformance (Current phase)
The first priority is to get Hamlet to conform to the ES5.1 Spec and pass as many Sputnik tests as is possible.
The second priority is speed. There are many optimisations that can be added to the code, once it's comformant.
In the parser there is much to be done to eliminate unecessary steps in the output code. For example, ToBoolean(x==true)
, etc.
In the runtime there are many optimisations that can be added to cater to LuaJIT.
The code is to be divided into core functionality and additional units of functionality (eg, Date, RegExp, etc), that can be added selectively.
A command line app should be able to the download an NPM package and its dependencies, translate them, add runtime and build a Lua module with the same interface.
Unicode is not supported by Lua and is therefore missing from Hamlet. If anyone has any ideas how Unicode could be added, please get in touch.
Implementation of eval() is postoned until the parser and its dependency can be translated to Lua.
This is low on the list of priorities due to its complexity and the fact that it's not often used.
It will be implemented in the future as a customisable option. In the meantime, the parser will throw an error when a with
statement is encountered.
Please be aware that Hamlet is under heavy development and there are existing plans for a lot of that which is yet to be implemented.
I'm happy to discuss the project with anyone who wants to get involved. Give me a shout at @paulcuth.
MIT