Skip to content

Difference Reference

hazzard993 edited this page Feb 9, 2019 · 2 revisions

Vararg / Spread operator

function x(...spread) {     // function x(...) in Lua
	print(...spread);
}

Arrays

Arrays start at 1 for Lua.

The TypescriptToLua transpiler uses 0-indexed arrays.

let a = [];
table.insert(a, true);
print(a[0]);    // transpiled version prints true

Multi-return

Javascript cannot return multiple values, but it can destructure them.

function tuple() {
	return [3, 4, 5];
}
let [a, b, c] = tuple();    // Array destructure
print(a, b, c);             // 3, 4, 5

Classes

class Player {
    constructor() {}
    update() {}
    draw() {}
}
let p = new Player();
p.draw();           // transpiles to p:draw()
Clone this wiki locally