isaacscript-common 1.2.215 → 1.2.216

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.
@@ -8,9 +8,10 @@ local SerializationType = ____SerializationType.SerializationType
8
8
  local ____table = require("functions.table")
9
9
  local copyValuesToTable = ____table.copyValuesToTable
10
10
  local getNumbersFromTable = ____table.getNumbersFromTable
11
+ local ____userdata = require("functions.userdata")
12
+ local isUserdataObject = ____userdata.isUserdataObject
11
13
  local ____utils = require("functions.utils")
12
14
  local ensureAllCases = ____utils.ensureAllCases
13
- local isUserdataObject = ____utils.isUserdataObject
14
15
  function ____exports.isColor(self, object)
15
16
  return isUserdataObject(nil, object, OBJECT_NAME)
16
17
  end
@@ -35,6 +35,8 @@ local ____set = require("functions.set")
35
35
  local getSortedSetValues = ____set.getSortedSetValues
36
36
  local ____trinkets = require("functions.trinkets")
37
37
  local getTrinketName = ____trinkets.getTrinketName
38
+ local ____userdata = require("functions.userdata")
39
+ local getUserdataType = ____userdata.getUserdataType
38
40
  local ____utils = require("functions.utils")
39
41
  local printConsole = ____utils.printConsole
40
42
  function ____exports.getDebugPrependString(self, msg, numParentFunctions)
@@ -430,7 +432,12 @@ function ____exports.logUserdata(userdata)
430
432
  ____exports.log("Userdata: [no metatable]")
431
433
  return
432
434
  end
433
- ____exports.log("Userdata: " .. metatable.__type)
435
+ local classType = getUserdataType(nil, userdata)
436
+ if classType == nil then
437
+ ____exports.log("Userdata: [no class type]")
438
+ else
439
+ ____exports.log("Userdata: " .. classType)
440
+ end
434
441
  ____exports.logTable(metatable)
435
442
  end
436
443
  function ____exports.logVector(vector)
@@ -11,9 +11,10 @@ local SerializationType = ____SerializationType.SerializationType
11
11
  local ____table = require("functions.table")
12
12
  local getNumbersFromTable = ____table.getNumbersFromTable
13
13
  local tableHasKeys = ____table.tableHasKeys
14
+ local ____userdata = require("functions.userdata")
15
+ local isUserdataObject = ____userdata.isUserdataObject
14
16
  local ____utils = require("functions.utils")
15
17
  local ensureAllCases = ____utils.ensureAllCases
16
- local isUserdataObject = ____utils.isUserdataObject
17
18
  function ____exports.getRandomSeed(self)
18
19
  local randomNumber = Random()
19
20
  local safeRandomNumber = randomNumber == 0 and 1 or randomNumber
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Helper function to get the type of a userdata object from the Isaac API. This is contained within
3
+ * the "__type" metatable key.
4
+ *
5
+ * For example, a `Vector` class is userdata with a type of "Vector".
6
+ */
7
+ export declare function getUserdataType(object: unknown): string | undefined;
8
+ /**
9
+ * Helper function to check if something is an instantiated class from the Isaac API. (All classes
10
+ * from the Isaac API have a type of "userdata" in Lua with a metatable key of "__type".)
11
+ */
12
+ export declare function isUserdataObject(object: unknown, objectType: string): boolean;
@@ -0,0 +1,18 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ function ____exports.getUserdataType(self, object)
4
+ local objectType = type(object)
5
+ if objectType ~= "userdata" then
6
+ return nil
7
+ end
8
+ local metatable = getmetatable(object)
9
+ if metatable == nil then
10
+ return nil
11
+ end
12
+ return metatable.__type
13
+ end
14
+ function ____exports.isUserdataObject(self, object, objectType)
15
+ local userdataType = ____exports.getUserdataType(nil, object)
16
+ return userdataType == objectType or userdataType == "const " .. objectType
17
+ end
18
+ return ____exports
@@ -93,11 +93,6 @@ export declare function hexToKColor(hexString: string, alpha: float): KColor;
93
93
  * is enabled or not.
94
94
  */
95
95
  export declare function isLuaDebugEnabled(): boolean;
96
- /**
97
- * Helper function to check if the something is an instantiated class from the Isaac API. (All
98
- * classes from the Isaac API have a type of "userdata" in Lua.)
99
- */
100
- export declare function isUserdataObject(object: unknown, objectName: string): boolean;
101
96
  /**
102
97
  * Helper function to print something to the in-game console. Use this instead of invoking the
103
98
  * `Isaac.ConsoleOutput` method directly because it will automatically insert a newline at the end
@@ -66,18 +66,6 @@ end
66
66
  function ____exports.isLuaDebugEnabled(self)
67
67
  return package ~= nil
68
68
  end
69
- function ____exports.isUserdataObject(self, object, objectName)
70
- local objectType = type(object)
71
- if objectType ~= "userdata" then
72
- return false
73
- end
74
- local metatable = getmetatable(object)
75
- if metatable == nil then
76
- return false
77
- end
78
- local vectorMetatable = metatable
79
- return vectorMetatable.__type == objectName
80
- end
81
69
  function ____exports.printConsole(self, msg)
82
70
  Isaac.ConsoleOutput(msg .. "\n")
83
71
  end
@@ -11,9 +11,10 @@ local ____table = require("functions.table")
11
11
  local copyValuesToTable = ____table.copyValuesToTable
12
12
  local getNumbersFromTable = ____table.getNumbersFromTable
13
13
  local tableHasKeys = ____table.tableHasKeys
14
+ local ____userdata = require("functions.userdata")
15
+ local isUserdataObject = ____userdata.isUserdataObject
14
16
  local ____utils = require("functions.utils")
15
17
  local ensureAllCases = ____utils.ensureAllCases
16
- local isUserdataObject = ____utils.isUserdataObject
17
18
  function ____exports.isVector(self, object)
18
19
  return isUserdataObject(nil, object, OBJECT_NAME)
19
20
  end
package/dist/index.d.ts CHANGED
@@ -88,6 +88,7 @@ export * from "./functions/trinketGive";
88
88
  export * from "./functions/trinkets";
89
89
  export * from "./functions/trinketSet";
90
90
  export * from "./functions/ui";
91
+ export * from "./functions/userdata";
91
92
  export * from "./functions/utils";
92
93
  export * from "./functions/vector";
93
94
  export * from "./maps/cardMap";
package/dist/index.lua CHANGED
@@ -704,6 +704,14 @@ do
704
704
  end
705
705
  end
706
706
  end
707
+ do
708
+ local ____export = require("functions.userdata")
709
+ for ____exportKey, ____exportValue in pairs(____export) do
710
+ if ____exportKey ~= "default" then
711
+ ____exports[____exportKey] = ____exportValue
712
+ end
713
+ end
714
+ end
707
715
  do
708
716
  local ____export = require("functions.utils")
709
717
  for ____exportKey, ____exportValue in pairs(____export) do
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.215",
3
+ "version": "1.2.216",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",