@tilua-types/roblox 4.0.0 → 4.2.0

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/index.d.tilua CHANGED
@@ -66,6 +66,7 @@ declare debug: {
66
66
  info: (...args: unknown[]) => unknown,
67
67
  profilebegin: (label: string) => nil,
68
68
  profileend: () => nil,
69
+ getmemorycategory: () => string,
69
70
  setmemorycategory: (tag: string) => nil,
70
71
  resetmemorycategory: () => nil,
71
72
  dumpcodesize: () => nil,
@@ -99,6 +100,11 @@ declare math: {
99
100
  isnan: (n: number) => boolean,
100
101
  isinf: (n: number) => boolean,
101
102
  isfinite: (n: number) => boolean,
103
+ nan: number,
104
+ e: number,
105
+ phi: number,
106
+ sqrt2: number,
107
+ tau: number,
102
108
  }
103
109
 
104
110
  declare table: {
@@ -8679,7 +8685,7 @@ declare script: LuaSourceContainer
8679
8685
  declare plugin: Plugin
8680
8686
  declare game: DataModel
8681
8687
  declare workspace: Workspace
8682
- declare shared: any
8688
+ declare shared: { [string]: unknown }
8683
8689
  declare task: { synchronize: () => nil, desynchronize: () => nil, defer: <A extends unknown[], R>(threadOrFunction: thread | ((...args: A) => R), ...args: A) => thread, spawn: <A extends unknown[], R>(threadOrFunction: thread | ((...args: A) => R), ...args: A) => thread, delay: <A extends unknown[], R>(duration?: number, threadOrFunction: thread | ((...args: A) => R), ...args: A) => thread, wait: (duration?: number) => number, cancel: (thread: thread) => nil }
8684
8690
  type NotificationButton = { Text: string, ButtonType: Enum.NotificationButtonType, OnActivated: () => any }
8685
8691
  type NotificationInfo = { Title?: string, Text?: string, Icon?: string, Buttons?: NotificationButton[], OnDisplay?: () => any, OnDismiss?: () => any }
package/lowering.mjs CHANGED
@@ -26,9 +26,9 @@
26
26
  import { readFileSync } from "node:fs"
27
27
  import { dirname, join } from "node:path"
28
28
  import { fileURLToPath } from "node:url"
29
+ import { hasMembers, isInstanceOf, luauString, returnsTuple } from "@tilua/parser"
29
30
 
30
31
  /** @typedef {import("@tilua/parser").LoweringPlugin} LoweringPlugin */
31
- /** @typedef {import("@tilua/parser").Type} Type */
32
32
 
33
33
  const here = dirname(fileURLToPath(import.meta.url))
34
34
  const roblox = readFileSync(join(here, "runtime", "roblox.luau"), "utf8")
@@ -43,58 +43,23 @@ const SERVICE_METHODS = new Map([
43
43
  ["BindActionAtPriority", "ContextActionService"],
44
44
  ])
45
45
 
46
- /** The members of a type that may be nil: a check the analyzer asked for
47
- * elsewhere, not a reason to lower differently here.
48
- * @type {(type: Type | undefined) => Type[]} */
49
- function parts(type) {
50
- if (!type) return []
51
- if (type.kind !== "union") return [type]
52
- return type.types.filter(m => !(m.kind === "primitive" && m.name === "nil"))
53
- }
54
-
55
46
  /** `RBXScriptSignal<T...>` is structural once it is resolved: an object that
56
- * can be connected to and waited on.
57
- * @type {(type: Type | undefined) => boolean} */
58
- function isSignal(type) {
59
- const members = parts(type)
60
- return members.length > 0 && members.every(m =>
61
- m.kind === "object" && m.properties.has("Connect") && m.properties.has("Once") && m.properties.has("Wait"))
62
- }
47
+ * can be connected to and waited on. */
48
+ const SIGNAL_MEMBERS = ["Connect", "Once", "Wait"]
63
49
 
64
50
  /** Luau globals answering several values, which the runtime gathers. */
65
51
  const GATHERED_GLOBALS = new Set(["string.unpack", "coroutine.close", "utf8.codepoint", "utf8.codes", "utf8.graphemes"])
66
52
 
67
- /** Does every signature of `receiver`'s `method` return a tuple — several
68
- * values, as tilua has them in one array?
69
- * @type {(receiver: Type | undefined, method: string) => boolean} */
70
- function returnsSeveral(receiver, method) {
71
- const members = parts(receiver)
72
- if (!members.length) return false
73
- return members.every(m => {
74
- if (m.kind !== "object") return false
75
- const found = m.properties.get(method)?.type
76
- const signatures = !found ? [] : found.kind === "intersection" ? found.types : [found]
77
- return signatures.length > 0 && signatures.every(f => f.kind === "function" && f.returns.kind === "tuple")
78
- })
79
- }
80
-
81
- /** @type {(type: Type | undefined, className: string) => boolean} */
82
- function isInstanceOf(type, className) {
83
- const members = parts(type)
84
- return members.length > 0 && members.every(m =>
85
- m.kind === "object" && m.class !== undefined && m.class.ancestors.includes(className))
86
- }
87
-
88
53
  /** @type {LoweringPlugin} */
89
54
  const plugin = {
90
55
  runtime: { roblox },
91
56
 
92
57
  methodCall({ method, receiver, use }) {
93
- if (SIGNAL_METHODS.has(method) && isSignal(receiver)) return { callee: `${use("roblox")}.${method}` }
58
+ if (SIGNAL_METHODS.has(method) && hasMembers(receiver, SIGNAL_MEMBERS)) return { callee: `${use("roblox")}.${method}` }
94
59
  const service = SERVICE_METHODS.get(method)
95
60
  if (service !== undefined && isInstanceOf(receiver, service)) return { callee: `${use("roblox")}.${method}` }
96
- if (returnsSeveral(receiver, method)) {
97
- return { callee: `${use("roblox")}.values`, prepend: [JSON.stringify(method)] }
61
+ if (returnsTuple(receiver, method)) {
62
+ return { callee: `${use("roblox")}.values`, prepend: [luauString(method)] }
98
63
  }
99
64
  return undefined
100
65
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tilua-types/roblox",
3
- "version": "4.0.0",
3
+ "version": "4.2.0",
4
4
  "description": "Luau and the whole Roblox API as tilua types: every class, enum, data type, service and global",
5
5
  "license": "ISC",
6
6
  "files": [
@@ -14,8 +14,11 @@
14
14
  "types": "index.d.tilua",
15
15
  "lowering": "lowering.mjs"
16
16
  },
17
+ "peerDependencies": {
18
+ "@tilua/parser": "^3.1.0"
19
+ },
17
20
  "dependencies": {
18
- "@tilua-types/lua": "^4.0.0"
21
+ "@tilua-types/lua": "^4.1.0"
19
22
  },
20
23
  "keywords": [
21
24
  "tilua",