Skip to content

Commit aab2763

Browse files
authored
fix bad printer example (#84)
* fixing broken printer example * prettier
1 parent 5052022 commit aab2763

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

docs/api/plugins.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,27 @@ export default plugin;
7575

7676
### `printer`
7777

78-
Printer is a function that overrides standard implementation of Lua AST printer. It receives some information about the file and transformed Lua AST. See [Printer](printer.md) page for more information.
78+
`printer` is a function that overrides the standard implementation of the Lua AST printer. It receives some information about the file and the transformed Lua AST. See the [LuaPrinter](printer.md) page for more information.
7979

8080
Example:
8181

8282
```ts
83+
import * as ts from "typescript";
8384
import * as tstl from "typescript-to-lua";
8485

85-
class CustomLuaPrinter extends tstl.LuaPrinter {}
86+
const CUSTOM_COMMENT_HEADER = "-- This code was generated with a custom plugin!\n";
87+
88+
class CustomLuaPrinter extends tstl.LuaPrinter {
89+
printCustom(file: tstl.File) {
90+
const printResult = this.print(file);
91+
printResult.code = CUSTOM_COMMENT_HEADER + printResult.code;
92+
return printResult;
93+
}
94+
}
8695

8796
const plugin: tstl.Plugin = {
88-
printer: (program, emitHost, fileName, block, luaLibFeatures) =>
89-
new CustomLuaPrinter(program.getCompilerOptions(), emitHost, fileName).print(block, luaLibFeatures),
97+
printer: (program: ts.Program, emitHost: tstl.EmitHost, fileName: string, file: tstl.File) =>
98+
new CustomLuaPrinter(emitHost, program, fileName).printCustom(file),
9099
};
91100

92101
export default plugin;

0 commit comments

Comments
 (0)