Home

Awesome

lua-js-syntax

This is a transpiler from an alternative JS-inspired syntax for Lua to vanilla Lua.

Advantages:

Disadvantages:

Alternative projects

Comparison with Lua

<table><tr><th>LuaJS</th><th>Lua</th></tr> <tr> <td>
/* A simple division function. */
let divide = (x, y) => {
    if (y == 0) {
        throw "Divisor is zero"
    }
    return x / y
}

try {
    print('Result is ' .. divide(10, 0))
} catch (e) {
    print('Error: ' .. e)
}

</td> <td>
--[[ A simple division function. ]]--
local divide = function(x, y)
    if (y == 0) then
        error("Divisor is zero")
    end
    return x / y
end

local res, e = pcall(function()
    print('Result is ' .. tostring(divide(10, 0)))
end)
if not res then
    print('Error: ' .. tostring(e))
end
</td> </tr> </table>

See COMPARISON.md for full comparison.

Building

To build, you need:

This will put JAR file to target dir and install it into local Maven repository:

git clone https://github.com/saharNooby/lua-js-syntax.git
cd lua-js-syntax
mvn clean install

Running

After build, you can either add this converter as a Maven dependency and use it from JVM-based language (Java, Kotlin, Scala etc.), or run it from console.

Add as a dependency

Maven dependency:

<dependency>
    <groupId>me.saharnooby</groupId>
    <artifactId>lua-js-syntax</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

Alternatively, you can just add the shaded JAR as a dependency directly to your build system.

Then you can use method me.saharnooby.luajssyntax.LuaJSToLua.convert(java.lang.String) or me.saharnooby.luajssyntax.LuaJSToLua.convert(java.lang.String, java.lang.Appendable). JavaDoc is available.

Run from console

If the source file was not specified, source code will be read from stdin.

If the destination file was not specified, resulting code will be written to stdout.

Any errors will result in non-zero exit code and stacktraces printed to stderr.

Testing

The project has a list of unit tests comparing LuaJS code behavior to the behavior of manually written equivalent Lua code.