isaacscript 2.16.0 → 2.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
{ "name": "isaacscript/src/plugins/addIsaacScriptCommentHeader.js" },
|
|
27
27
|
|
|
28
28
|
// A plugin to make enums safe from global variables.
|
|
29
|
-
{ "name": "isaacscript/src/plugins/noExtendedEnums.
|
|
29
|
+
{ "name": "isaacscript/src/plugins/noExtendedEnums.js" },
|
|
30
30
|
|
|
31
31
|
// Uncomment this and recompile the mod to enable crash debugging, which will tell you the
|
|
32
32
|
// exact line of the mod that is causing the crash.
|
package/package.json
CHANGED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* When you write code that causes the game to crash, it can be difficult to find the exact line of
|
|
3
|
-
* code that is causing the crash.
|
|
4
|
-
*
|
|
5
|
-
* In these situations, you can enable this plugin, which will add a log statement in between every
|
|
6
|
-
* line of Lua code with a randomly-generated UUID. That way, you can cause the crash, and then look
|
|
7
|
-
* at the bottom of the "log.txt" for the final UUID that shows up.
|
|
8
|
-
*
|
|
9
|
-
* Next, you can Ctrl + f in the "main.lua" file for the matching UUID, which will bring you to the
|
|
10
|
-
* exact point in the code where the crash happened.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import * as crypto from "crypto";
|
|
14
|
-
import { SourceNode } from "source-map";
|
|
15
|
-
import * as ts from "typescript";
|
|
16
|
-
import * as tstl from "typescript-to-lua";
|
|
17
|
-
|
|
18
|
-
class CustomPrinter extends tstl.LuaPrinter {
|
|
19
|
-
printStatement(statement: tstl.Statement): SourceNode {
|
|
20
|
-
const uuid = crypto.randomUUID();
|
|
21
|
-
const debugLineToInsert = `Isaac.DebugString("CRASH DEBUG ${uuid}")\n`;
|
|
22
|
-
const originalResult = super.printStatement(statement);
|
|
23
|
-
return this.createSourceNode(statement, [
|
|
24
|
-
debugLineToInsert,
|
|
25
|
-
originalResult,
|
|
26
|
-
]);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const plugin: tstl.Plugin = {
|
|
31
|
-
printer: (
|
|
32
|
-
program: ts.Program,
|
|
33
|
-
emitHost: tstl.EmitHost,
|
|
34
|
-
fileName: string,
|
|
35
|
-
file: tstl.File,
|
|
36
|
-
) => new CustomPrinter(emitHost, program, fileName).print(file),
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// ts-prune-ignore-next
|
|
40
|
-
export default plugin;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/** This plugin adds an explanatory header to the top of the generated Lua code. */
|
|
2
|
-
|
|
3
|
-
import * as ts from "typescript";
|
|
4
|
-
import * as tstl from "typescript-to-lua";
|
|
5
|
-
|
|
6
|
-
const INFORMATIONAL_HEADER = `--[[
|
|
7
|
-
|
|
8
|
-
This Isaac mod was created with the IsaacScript tool.
|
|
9
|
-
|
|
10
|
-
The Lua code in this file is not actually the source code for the program. Rather, it was
|
|
11
|
-
automatically generated from higher-level TypeScript code, and might be hard to read. If you want to
|
|
12
|
-
understand how the code in this mod works, you should read the actual TypeScript source code
|
|
13
|
-
directly instead of trying to read this file. Usually, the link to the source code can be found in
|
|
14
|
-
the mod's description on the Steam Workshop. If not, you can ask the mod author directly if the
|
|
15
|
-
source code is publicly available.
|
|
16
|
-
|
|
17
|
-
IsaacScript provides a lot of advantages over using raw Lua. For more information about the tool,
|
|
18
|
-
see the official website: https://isaacscript.github.io/
|
|
19
|
-
|
|
20
|
-
--]]
|
|
21
|
-
|
|
22
|
-
`;
|
|
23
|
-
|
|
24
|
-
const plugin: tstl.Plugin = {
|
|
25
|
-
beforeEmit(
|
|
26
|
-
_program: ts.Program,
|
|
27
|
-
_options: tstl.CompilerOptions,
|
|
28
|
-
_emitHost: tstl.EmitHost,
|
|
29
|
-
result: tstl.EmitFile[],
|
|
30
|
-
) {
|
|
31
|
-
for (const file of result) {
|
|
32
|
-
file.code = `${INFORMATIONAL_HEADER}${file.code}`;
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default plugin;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This plugin prevents transpiled enums from using global variables as a base (if present).
|
|
3
|
-
*
|
|
4
|
-
* For example, by default, the following enum:
|
|
5
|
-
*
|
|
6
|
-
* ```ts
|
|
7
|
-
* export enum Foo {
|
|
8
|
-
* Value1,
|
|
9
|
-
* Value2,
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Will be transpiled to this:
|
|
14
|
-
*
|
|
15
|
-
* ```lua
|
|
16
|
-
* local ____exports = {}
|
|
17
|
-
* ____exports.Foo = Foo or ({})
|
|
18
|
-
* ____exports.Foo.Value1 = 0
|
|
19
|
-
* ____exports.Foo[____exports.Foo.Value1] = "Value1"
|
|
20
|
-
* ____exports.Foo.Value2 = 1
|
|
21
|
-
* ____exports.Foo[____exports.Foo.Value2] = "Value2"
|
|
22
|
-
* return ____exports
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* As we can see, the first line uses the existing global variable of "Foo" as a base, if present.
|
|
26
|
-
* The reason it does this is because TSTL needs to support the TypeScript feature of combining
|
|
27
|
-
* enums, like this:
|
|
28
|
-
*
|
|
29
|
-
* ```ts
|
|
30
|
-
* enum Foo {
|
|
31
|
-
* Value1,
|
|
32
|
-
* }
|
|
33
|
-
* enum Foo {
|
|
34
|
-
* Value2,
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* Unfortunately, this design decision means that local enums will essentially turn into global
|
|
39
|
-
* variables. This plugin removes this behavior, always making enums local variables.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
import * as ts from "typescript";
|
|
43
|
-
import * as tstl from "typescript-to-lua";
|
|
44
|
-
|
|
45
|
-
const plugin: tstl.Plugin = {
|
|
46
|
-
visitors: {
|
|
47
|
-
[ts.SyntaxKind.EnumDeclaration]: (node, context) => {
|
|
48
|
-
// Call the normal TSTL enum transpilation method
|
|
49
|
-
const statements = context.superTransformStatements(node);
|
|
50
|
-
|
|
51
|
-
// Get the first element, which will be equal to something like:
|
|
52
|
-
// local ____exports.Foo = Foo or ({})
|
|
53
|
-
const oldDeclaration = statements[0];
|
|
54
|
-
if (
|
|
55
|
-
oldDeclaration !== undefined &&
|
|
56
|
-
tstl.isAssignmentStatement(oldDeclaration)
|
|
57
|
-
) {
|
|
58
|
-
// Replace the right side of the assignment with a blank Lua table, e.g.
|
|
59
|
-
// local ____exports.Foo = {}
|
|
60
|
-
const blankTable = tstl.createTableExpression();
|
|
61
|
-
oldDeclaration.right = [blankTable];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return statements;
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export default plugin;
|