You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Chnage prettier options
* Enable prettier on all files
* Remove formatting rules from main tslint config
* Format all files with prettier
* Make some manual formatting changes
To get familiar with the project structure, here is a short overview of each directory and their function.
11
+
10
12
-`src/`
11
-
* Source code for the project, has the transpiler core files in its root.
12
-
*`src/lualib/`
13
+
- Source code for the project, has the transpiler core files in its root.
14
+
-`src/lualib/`
13
15
- Contains the TypeScript source for the lualib. This consists of implementations of standard TypeScript functions that are not present in Lua. These files are compiled to Lua using the transpiler. They are included in the Lua result when transpiling.
14
-
*`src/targets/`
16
+
-`src/targets/`
15
17
- Version-specific transpiler overrides for the different Lua targets. The main transpiler transpiles Lua 5.0, each target-specific transpiler extends the transpiler of the version before it, so the 5.3 inherits 5.2 which inherits 5.1 which inherits 5.0. LuaJIT is based on 5.2 so inherits from the 5.2 transpiler.
16
-
**Compiler.ts* - Main entry point of the transpiler, this is what interfaces with the TypeScript compiler API.
17
-
**LuaTransformer.ts* - Main transpiler code, transforms a TypeScript AST to a Lua AST.
18
-
**LuaPrinter.ts* - Transforms a Lua AST to a string.
19
-
**TSHelper.ts* - Helper methods used during the transpilation process.
18
+
-_Compiler.ts_ - Main entry point of the transpiler, this is what interfaces with the TypeScript compiler API.
19
+
-_LuaTransformer.ts_ - Main transpiler code, transforms a TypeScript AST to a Lua AST.
20
+
-_LuaPrinter.ts_ - Transforms a Lua AST to a string.
21
+
-_TSHelper.ts_ - Helper methods used during the transpilation process.
20
22
-`test/`
21
-
* This directory contains all testing code for the transpiler.
22
-
*`test/unit/`
23
+
- This directory contains all testing code for the transpiler.
24
+
-`test/unit/`
23
25
- Unit/Functional tests for the transpiler. Tests in here are grouped by functionality they are testing. Generally each of these tests uses the transpiler to transpile some TypeScript to Lua, then executes it using the Fengari Lua VM. Assertion is done on the result of the lua code.
24
-
*`test/translation/`
26
+
-`test/translation/`
25
27
-**[Obsolete]** Contains tests that only check the transpiled Lua String. We prefer adding unit/functional tests over translation tests. This directory will probably be removed at some point.
26
28
27
29
## Running Tests
30
+
28
31
The tests for this project can be executed using the standard `npm test`. This runs all tests.
29
32
30
33
Due to the time required to run all tests, it is impractical to run every test while developing part of the transpiler. To speed up the test run you can:
@@ -46,14 +49,17 @@ Due to the time required to run all tests, it is impractical to run every test w
46
49
```
47
50
48
51
## Testing Guidelines
52
+
49
53
When submitting a pull request with new functionality, we require some functional (transpile and execute Lua) to be added, to ensure the new functionality works as expected, and will continue to work that way.
50
54
51
55
Translation tests are discouraged as in most cases as we do not really care about the exact Lua output, as long as executing it results in the correct result (which is tested by functional tests).
52
56
53
57
## Coding Conventions
58
+
54
59
Most coding conventions are enforced by the TSLint and Prettier. You can check your code locally by running `npm run lint`. The CI build will fail if your code does not pass the linter. For better experience, you can install extensions for your code editor for [TSLint](https://palantir.github.io/tslint/usage/third-party-tools/) and [Prettier](https://prettier.io/docs/en/editors.html).
55
60
56
61
Some extra conventions worth mentioning:
57
-
* Do not abbreviate variable names. The exception here are inline lambda arguments, if it is obvious what the argument is you can abbreviate to the first letter, e.g: `statements.filter(s => ts.VariableStatement(s))`
58
-
* Readability of code is more important than the amount of space it takes. If extra line breaks make your code more readable, add them.
59
-
* Functional style is encouraged!
62
+
63
+
- Do not abbreviate variable names. The exception here are inline lambda arguments, if it is obvious what the argument is you can abbreviate to the first letter, e.g: `statements.filter(s => ts.VariableStatement(s))`
64
+
- Readability of code is more important than the amount of space it takes. If extra line breaks make your code more readable, add them.
Copy file name to clipboardExpand all lines: README.md
+17-9Lines changed: 17 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ A generic TypeScript to Lua transpiler. Write your code in TypeScript and publis
15
15
Large projects written in lua can become hard to maintain and make it easy to make mistakes. Writing code in TypeScript instead improves maintainability, readability and robustness, with the added bonus of good IDE support. This project is useful in any environment where Lua code is accepted, with the powerful option of simply declaring any existing API using TypeScript declaration files.
16
16
17
17
## Documentation
18
+
18
19
More detailed documentation and info on writing declarations can be found [on the wiki](https://github.com/TypeScriptToLua/TypescriptToLua/wiki).
19
20
20
21
Changelog can be found in [CHANGELOG.md](https://github.com/TypeScriptToLua/TypescriptToLua/blob/master/CHANGELOG.md)
@@ -38,24 +39,28 @@ Changelog can be found in [CHANGELOG.md](https://github.com/TypeScriptToLua/Type
38
39
`tstl -p path/to/tsconfig.json --watch`
39
40
40
41
**Example tsconfig.json**
42
+
41
43
```json
42
44
{
43
-
"compilerOptions": {
44
-
"target": "esnext",
45
-
"lib": ["esnext"],
46
-
"strict": true
47
-
},
48
-
"tstl": {
49
-
"luaTarget": "JIT"
50
-
}
45
+
"compilerOptions": {
46
+
"target": "esnext",
47
+
"lib": ["esnext"],
48
+
"strict": true
49
+
},
50
+
"tstl": {
51
+
"luaTarget": "JIT"
52
+
}
51
53
}
52
54
```
53
55
54
56
## Contributing
57
+
55
58
All contributions are welcome, but please read our [contribution guidelines](https://github.com/TypeScriptToLua/TypescriptToLua/blob/master/CONTRIBUTING.md)!
56
59
57
60
## Declarations
61
+
58
62
The real power of this transpiler is usage together with good declarations for the Lua API provided. Some examples of Lua interface declarations can be found here:
-[Defold Game Engine Scripting](https://github.com/dasannikov/DefoldTypeScript/blob/master/defold.d.ts)
61
66
-[LÖVE 2D Game Development](https://github.com/hazzard993/love-typescript-definitions)
@@ -71,17 +76,20 @@ The real power of this transpiler is usage together with good declarations for t
71
76
`npm run coverage` or `npm run coverage-html` to generate a coverage report.
72
77
73
78
## Sublime Text integration
79
+
74
80
This compiler works great in combination with the [Sublime Text Typescript plugin](https://github.com/Microsoft/TypeScript-Sublime-Plugin) (available through the package manager as `TypeScript`).
75
81
76
82
You can simply open your typescript project assuming a valid tsconfig.json file is present. The default TypeScript plugin will provide all functionality of a regular TypeScript project.
77
83
78
84
### Setting up a custom build system
79
-
To add the option to build with the Lua transpiler instead of the regular typescript compiler, go to `Tools > Build System > New Build System...`. In the new sublime-build file that opens, enter the following (adjust path to tstl if not installed globally):
85
+
86
+
To add the option to build with the Lua transpiler instead of the regular typescript compiler, go to `Tools > Build System > New Build System...`. In the new sublime-build file that opens, enter the following (adjust path to tstl if not installed globally):
80
87
81
88
```
82
89
{
83
90
"cmd": ["tstl", "-p", "$file"],
84
91
"shell": true
85
92
}
86
93
```
94
+
87
95
Save this in your Sublime settings as a `TypeScriptToLua.sublime-build`. You can now select the TypeScriptToLua build system in `Tools > Build System` to build using the normal hotkey (`ctrl+B`), or if you have multiple TypeScript projects open, you can choose your compiler before building by pressing `ctrl+shift+B`.
0 commit comments