This transpiler target is called lua
and can be used to transpile Typescript into LUA. The emitted lua output is compatible with LUA version 5.1. I am sure that newer LUA version are supported as well, but i havn't tested it.
- Classes and heritage
- Class expressions
- New expressions
- Interfaces (Will be omitted in the output)
- Enums
- Named module and namespace imports
- Named and namespace exports
- Multiple return values (See below)
- Functions and arrowfunctions including signature overload
- Delete operator
- Variable declarations
- Literal expressions
- Prefix and suffix unary expressions
- Binary expressions including bitops
- Template strings
- Typeof and instanceof statements
- For, ForIn, ForOf, Do and While statements
- Spread element in every context
- Computed properties
- Regular expressions (only as literal)
- Builtin Array functions
- Array.join()
- Array.push()
- Array.unshift()
- Array.forEach()
- Array.map()
- Array.filter()
- Array.some()
- Array.slice() (only positive index)
- Builtin String functions
- Builtin Object functions
- Builtin Function methods
- Builtin Math functions
- The lua equivalent will be used. See the lua documentation for more help.
- Builtin
.toString(base?)
function with base 10, 16 and no given base support. - Switch statements
- If, else, elseif
- Try catch finally
- Throw statement
- Type casts (Will be omitted in the emitted files)
- Conditional expressions (Tenary expressions)
- Magic properties
- Decorators
- Class level decorators (experimental support)
- Property level decorator
- Method level decorator (Not fully supported)
- Parameter level decorator (Partial support. Will be transpiled as parameter assignment:
param = Decorator(...)
) - Decorator factories
- Array and
objectdestructing
- Lua does not know about the difference between the
let
andconst
statement. Same as javascriptES5
. These are just hints at compilertime and will be lost at runtime. - The keywords
null
andundefined
will both be transpiled tonil
. So a testnull === undefined
will transpiled into a truethy expression:nil == nil
! - Use the array destructing pattern for achiving multireturn like results. See this example:
// myTypescriptFile.ts
const [a, b, c, , e] = myMultiReturnFunction()
Will be transpiled to:
-- theGeneratedLuaFile.lua
local a, b, c, _, e = myMultiReturnFunction()
- To support multireturn the tuple or array literal is used to achive this. When returning an array literal, the transpiler will use a multireturn. If a variable is returned, no matter the type, it will not be a multireturn. Example:
// this function will return multiple values
function myFunc(): [number, string] {
return [1, "test"]
}
// this function will NOT return multiple values
function myOtherFunc(): [number, string] {
const a = [1, "test"];
return a;
}
Will be transpiled to:
-- this function will return multiple values
local function myFunc()
return 1, "test"
end
-- this function will NOT return multiple values
local function myOtherFunc()
local a = {1, "test"}
return a
end
- Lua has no type reference to variables. But there is some kind of static reflection added at compiling time. Currently the following reflections are available via Bitop flag in the
qhun-transpiler.json
config entrystaticReflection
:
Number | Result |
---|---|
0 | No reflection at all |
1 | Class constructor signature analysis is written to constructor.__staticReflection |
2 | Class name is written to constructor.__name |
4 | Class namespace or folder path is written to constructor.__namespace |
Usage: Sum up the required reflection options and put the result in the json file. E.g: 1 (constructor signature) + 4 (class namespace) = 5
The number 5
will enable both selected features. In this example no class name is written into the transpiled file.
Each target has a config block section in the qhun-transpiler.json
file. So LUA does does. This block is currently empty and is reversed for future releases to configure the transpiling process.