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