isaacscript-common 13.3.0 → 13.3.2
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.
- package/dist/index.d.ts +12 -5
- package/dist/isaacscript-common.lua +17 -18
- package/dist/src/classes/ModUpgraded.d.ts.map +1 -1
- package/dist/src/classes/ModUpgraded.lua +8 -8
- package/dist/src/functions/log.d.ts +9 -2
- package/dist/src/functions/log.d.ts.map +1 -1
- package/dist/src/functions/log.lua +17 -10
- package/dist/src/indexLua.d.ts +185 -0
- package/dist/src/indexLua.d.ts.map +1 -0
- package/dist/src/indexLua.lua +1314 -0
- package/package.json +2 -2
- package/src/classes/ModUpgraded.ts +14 -7
- package/src/functions/log.ts +23 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "13.3.
|
|
3
|
+
"version": "13.3.2",
|
|
4
4
|
"description": "Helper functions and features for IsaacScript mods.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"isaac",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"main": "dist/src/index",
|
|
23
23
|
"types": "dist/src/index.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"isaac-typescript-definitions": "^7.2.
|
|
25
|
+
"isaac-typescript-definitions": "^7.2.9"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModCallback } from "isaac-typescript-definitions";
|
|
2
2
|
import { ModCallbackCustom } from "../enums/ModCallbackCustom";
|
|
3
3
|
import { getTime } from "../functions/benchmark";
|
|
4
|
-
import {
|
|
4
|
+
import { getParentFunctionDescription } from "../functions/log";
|
|
5
5
|
import { AddCallbackParameterCustom } from "../interfaces/private/AddCallbackParameterCustom";
|
|
6
6
|
import { CALLBACK_REGISTER_FUNCTIONS } from "../objects/callbackRegisterFunctions";
|
|
7
7
|
|
|
@@ -53,12 +53,19 @@ export class ModUpgraded implements Mod {
|
|
|
53
53
|
const callback = args[0];
|
|
54
54
|
const optionalArg = args[1];
|
|
55
55
|
|
|
56
|
+
const parentFunctionDescription = getParentFunctionDescription();
|
|
56
57
|
const callbackName = `ModCallback.${ModCallback[modCallback]}`;
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
const signature =
|
|
59
|
+
parentFunctionDescription === undefined
|
|
60
|
+
? callbackName
|
|
61
|
+
: `${parentFunctionDescription} - ${callbackName}`;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* We don't use the "log" helper function since it will always show the same "unknown" prefix.
|
|
65
|
+
*/
|
|
59
66
|
const callbackWithLogger = (...callbackArgs: unknown[]) => {
|
|
60
67
|
const startTime = getTime();
|
|
61
|
-
|
|
68
|
+
Isaac.DebugString(`${signature} - START`);
|
|
62
69
|
|
|
63
70
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
64
71
|
// @ts-expect-error
|
|
@@ -68,11 +75,11 @@ export class ModUpgraded implements Mod {
|
|
|
68
75
|
const elapsedTime = endTime - startTime;
|
|
69
76
|
if (
|
|
70
77
|
this.TimeThreshold === undefined ||
|
|
71
|
-
this.TimeThreshold
|
|
78
|
+
this.TimeThreshold <= elapsedTime
|
|
72
79
|
) {
|
|
73
|
-
|
|
80
|
+
Isaac.DebugString(`${signature} - END - time: ${elapsedTime}`);
|
|
74
81
|
} else {
|
|
75
|
-
|
|
82
|
+
Isaac.DebugString(`${signature} - END`);
|
|
76
83
|
}
|
|
77
84
|
};
|
|
78
85
|
|
package/src/functions/log.ts
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Helper function to
|
|
2
|
+
* Helper function to get the name and the line number of the current calling function.
|
|
3
|
+
*
|
|
4
|
+
* For this function to work properly, the "--luadebug" flag must be enabled. Otherwise, it will
|
|
5
|
+
* always return undefined.
|
|
6
|
+
*
|
|
7
|
+
* @param levels Optional. The amount of levels to look backwards in the call stack. Default is 3
|
|
8
|
+
* (because the first level is this function, the second level is the calling
|
|
9
|
+
* function, and the third level is the parent of the calling function).
|
|
3
10
|
*/
|
|
4
|
-
export function
|
|
5
|
-
msg: string,
|
|
11
|
+
export function getParentFunctionDescription(
|
|
6
12
|
// We use 3 as a default because:
|
|
7
|
-
// -
|
|
8
|
-
// -
|
|
9
|
-
// -
|
|
10
|
-
|
|
11
|
-
): string {
|
|
13
|
+
// - The first level is this function.
|
|
14
|
+
// - The second level is the calling function.
|
|
15
|
+
// - The third level is the parent of the calling function.
|
|
16
|
+
levels = 3,
|
|
17
|
+
): string | undefined {
|
|
12
18
|
// "debug" is not always defined like the Lua definitions imply.
|
|
13
19
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
14
20
|
if (debug !== undefined) {
|
|
15
21
|
// The "--luadebug" launch flag is enabled.
|
|
16
|
-
const debugTable = debug.getinfo(
|
|
22
|
+
const debugTable = debug.getinfo(levels);
|
|
17
23
|
if (debugTable !== undefined) {
|
|
18
|
-
return `${debugTable.name}:${debugTable.linedefined}
|
|
24
|
+
return `${debugTable.name}:${debugTable.linedefined}`;
|
|
19
25
|
}
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
if (SandboxGetParentFunctionDescription !== undefined) {
|
|
23
29
|
// The Racing+ sandbox is enabled.
|
|
24
|
-
|
|
25
|
-
numParentFunctions + 1,
|
|
26
|
-
);
|
|
27
|
-
return `${parentFunctionDescription} - ${msg}`;
|
|
30
|
+
return SandboxGetParentFunctionDescription(levels);
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
return
|
|
33
|
+
return undefined;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
/**
|
|
@@ -37,6 +40,10 @@ export function getDebugPrependString(
|
|
|
37
40
|
* function will also prepend the function name and the line number before the string.
|
|
38
41
|
*/
|
|
39
42
|
export function log(msg: string): void {
|
|
40
|
-
const
|
|
43
|
+
const parentFunctionDescription = getParentFunctionDescription();
|
|
44
|
+
const debugMsg =
|
|
45
|
+
parentFunctionDescription === undefined
|
|
46
|
+
? msg
|
|
47
|
+
: `${parentFunctionDescription} - ${msg}`;
|
|
41
48
|
Isaac.DebugString(debugMsg);
|
|
42
49
|
}
|