@tilua-types/roblox 4.1.0 → 5.0.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @tilua-types/roblox
2
2
 
3
3
  Luau and the whole Roblox API as tilua types: every class (921 of them), enum
4
- (633), data type, service and global, plus what Luau adds to Lua — `typeof`,
4
+ (633), data type, service and global, plus what Luau adds to Lua —
5
5
  `buffer`, `bit32`, `utf8`, `table.create`, `string.split`, `math.clamp`, ...
6
6
 
7
7
  Luau is Roblox's language, so the two ship together. Underneath is
@@ -27,7 +27,8 @@ tree, down to `script.Parent`.
27
27
  `declare class` (`Part extends FormFactorPart extends BasePart ...`). A
28
28
  `Part` passes wherever a `BasePart` or `Instance` is expected, but a
29
29
  `Folder` does not pass as a `Part`, and a table never passes as an
30
- `Instance`. `typeof(instance)` is `"Instance"`.
30
+ `Instance`. `typeof instance` is `"Instance"`: `TypeofNames` tells the
31
+ language's `typeof` what each Roblox value answers.
31
32
  - **Events with typed arguments.** In `Players.PlayerAdded:Connect(function(player) ... end)`,
32
33
  `player` is a `Player`. Callbacks assigned to a property, such as
33
34
  `remote.OnServerInvoke = function(player, ...)`, are typed the same way.
package/index.d.tilua CHANGED
@@ -11,13 +11,13 @@
11
11
  --
12
12
  -- Every Roblox type is a `declare class`: nominal, the way the engine sees it.
13
13
  -- A `Part` is an `Instance` because it extends one, and a table is never a
14
- -- `Part`. Classes are not tables, so `typeof(part)` is "Instance".
14
+ -- `Part`. Classes are not tables, so `typeof part` is "Instance".
15
15
  --
16
16
  -- `inst:IsA("Model")`, `game:GetService("Players")` and `Instance.new("Part")`
17
17
  -- are generic signatures over the maps at the end of this file: `K` infers the
18
18
  -- string literal that was passed, and the map gives back its class.
19
19
  --
20
- -- The file opens with what Luau adds to Lua 5.1 (`typeof`, `buffer`, `bit32`,
20
+ -- The file opens with what Luau adds to Lua 5.1 (`buffer`, `bit32`,
21
21
  -- ...), copied from scripts/luau.d.tilua — Luau is Roblox's, so they ship
22
22
  -- together. The Lua 5.1 standard library underneath is `@tilua-types/lua`.
23
23
 
@@ -32,28 +32,6 @@
32
32
  --
33
33
  -- Edit this file, then regenerate the Roblox definitions.
34
34
 
35
- -- ============================================================
36
- -- `typeof()`
37
- -- ------------------------------------------------------------
38
- -- Luau's own: `type()`'s answers plus the Roblox data types further down this
39
- -- file, which it reports by name rather than as `userdata`. Narrowing works
40
- -- exactly as it does for `type()` — see `@tilua-types/lua` for how the overloads
41
- -- drive it.
42
- -- ============================================================
43
-
44
- declare function typeof(value: nil): "nil"
45
- declare function typeof(value: boolean): "boolean"
46
- declare function typeof(value: number): "number"
47
- declare function typeof(value: string): "string"
48
- declare function typeof(value: thread): "thread"
49
- declare function typeof(value: buffer): "buffer"
50
- declare function typeof(value: (...args: unknown[]) => unknown): "function"
51
- declare function typeof(value: { [unknown]: unknown }): "table"
52
- declare function typeof<T>(value: T): string
53
-
54
- -- Luau's `type()` knows one answer Lua's does not.
55
- declare function type(value: buffer): "buffer"
56
-
57
35
  -- ============================================================
58
36
  -- Base library
59
37
  -- ============================================================
@@ -66,6 +44,7 @@ declare debug: {
66
44
  info: (...args: unknown[]) => unknown,
67
45
  profilebegin: (label: string) => nil,
68
46
  profileend: () => nil,
47
+ getmemorycategory: () => string,
69
48
  setmemorycategory: (tag: string) => nil,
70
49
  resetmemorycategory: () => nil,
71
50
  dumpcodesize: () => nil,
@@ -99,6 +78,11 @@ declare math: {
99
78
  isnan: (n: number) => boolean,
100
79
  isinf: (n: number) => boolean,
101
80
  isfinite: (n: number) => boolean,
81
+ nan: number,
82
+ e: number,
83
+ phi: number,
84
+ sqrt2: number,
85
+ tau: number,
102
86
  }
103
87
 
104
88
  declare table: {
@@ -8679,7 +8663,7 @@ declare script: LuaSourceContainer
8679
8663
  declare plugin: Plugin
8680
8664
  declare game: DataModel
8681
8665
  declare workspace: Workspace
8682
- declare shared: any
8666
+ declare shared: { [string]: unknown }
8683
8667
  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
8668
  type NotificationButton = { Text: string, ButtonType: Enum.NotificationButtonType, OnActivated: () => any }
8685
8669
  type NotificationInfo = { Title?: string, Text?: string, Icon?: string, Buttons?: NotificationButton[], OnDisplay?: () => any, OnDismiss?: () => any }
@@ -8939,7 +8923,7 @@ declare class Instance extends Object {
8939
8923
  UniqueId: UniqueId,
8940
8924
  AddTag: (self: Instance, tag: string) => nil,
8941
8925
  ClearAllChildren: (self: Instance) => nil,
8942
- Clone: (self: Instance) => Instance,
8926
+ Clone: <T extends Instance>(self: T) => T,
8943
8927
  Destroy: (self: Instance) => nil,
8944
8928
  FindFirstAncestor: <T = Instance>(self: Instance, name: string) => T | nil,
8945
8929
  FindFirstAncestorOfClass: <K extends keyof ClassMap>(self: Instance, className: K) => ClassMap[K] | nil,
@@ -19811,54 +19795,56 @@ type CreatableClassMap = {
19811
19795
  WrapTextureTransfer: WrapTextureTransfer,
19812
19796
  }
19813
19797
 
19814
- -- `type()` is "userdata" for every Roblox type; `typeof()` names the data
19815
- -- type, or says "Instance", "EnumItem", ... These add to the overloads in
19816
- -- the Luau layer above, and a class is never a table, so none of them is
19817
- -- "table".
19818
- declare function type(value: Axes | BrickColor | CFrame | CatalogSearchParams | Color3 | ColorSequence | ColorSequenceKeypoint | Content | DateTime | DockWidgetPluginGuiInfo | Faces | FloatCurveKey | Font | InstanceHandle | NumberRange | NumberSequence | NumberSequenceKeypoint | OverlapParams | Path2DControlPoint | PathWaypoint | PhysicalProperties | RBXScriptConnection | Random | Ray | RaycastParams | Rect | Region3 | Region3int16 | RotationCurveKey | Secret | SecurityCapabilities | SharedTable | TweenInfo | UDim | UDim2 | User | ValueCurveKey | Vector2 | Vector2int16 | Vector3 | Vector3int16 | Object | EnumItem | Enum | Enums): "userdata"
19819
- declare function typeof(value: Axes): "Axes"
19820
- declare function typeof(value: BrickColor): "BrickColor"
19821
- declare function typeof(value: CFrame): "CFrame"
19822
- declare function typeof(value: CatalogSearchParams): "CatalogSearchParams"
19823
- declare function typeof(value: Color3): "Color3"
19824
- declare function typeof(value: ColorSequence): "ColorSequence"
19825
- declare function typeof(value: ColorSequenceKeypoint): "ColorSequenceKeypoint"
19826
- declare function typeof(value: Content): "Content"
19827
- declare function typeof(value: DateTime): "DateTime"
19828
- declare function typeof(value: DockWidgetPluginGuiInfo): "DockWidgetPluginGuiInfo"
19829
- declare function typeof(value: Faces): "Faces"
19830
- declare function typeof(value: FloatCurveKey): "FloatCurveKey"
19831
- declare function typeof(value: Font): "Font"
19832
- declare function typeof(value: InstanceHandle): "InstanceHandle"
19833
- declare function typeof(value: NumberRange): "NumberRange"
19834
- declare function typeof(value: NumberSequence): "NumberSequence"
19835
- declare function typeof(value: NumberSequenceKeypoint): "NumberSequenceKeypoint"
19836
- declare function typeof(value: OverlapParams): "OverlapParams"
19837
- declare function typeof(value: Path2DControlPoint): "Path2DControlPoint"
19838
- declare function typeof(value: PathWaypoint): "PathWaypoint"
19839
- declare function typeof(value: PhysicalProperties): "PhysicalProperties"
19840
- declare function typeof(value: RBXScriptConnection): "RBXScriptConnection"
19841
- declare function typeof(value: Random): "Random"
19842
- declare function typeof(value: Ray): "Ray"
19843
- declare function typeof(value: RaycastParams): "RaycastParams"
19844
- declare function typeof(value: Rect): "Rect"
19845
- declare function typeof(value: Region3): "Region3"
19846
- declare function typeof(value: Region3int16): "Region3int16"
19847
- declare function typeof(value: RotationCurveKey): "RotationCurveKey"
19848
- declare function typeof(value: Secret): "Secret"
19849
- declare function typeof(value: SecurityCapabilities): "SecurityCapabilities"
19850
- declare function typeof(value: SharedTable): "SharedTable"
19851
- declare function typeof(value: TweenInfo): "TweenInfo"
19852
- declare function typeof(value: UDim): "UDim"
19853
- declare function typeof(value: UDim2): "UDim2"
19854
- declare function typeof(value: User): "User"
19855
- declare function typeof(value: ValueCurveKey): "ValueCurveKey"
19856
- declare function typeof(value: Vector2): "Vector2"
19857
- declare function typeof(value: Vector2int16): "Vector2int16"
19858
- declare function typeof(value: Vector3): "Vector3"
19859
- declare function typeof(value: Vector3int16): "Vector3int16"
19860
- declare function typeof(value: Instance): "Instance"
19861
- declare function typeof(value: Object): "Object"
19862
- declare function typeof(value: EnumItem): "EnumItem"
19863
- declare function typeof(value: Enum): "Enum"
19864
- declare function typeof(value: Enums): "Enums"
19798
+ -- What `typeof` answers for a Roblox value: the data type's own name, or
19799
+ -- "Instance", "EnumItem", ... Each property is the name `typeof` gives a
19800
+ -- value of the property's type, and a value several of them fit — a `Part`
19801
+ -- is an `Instance` and an `Object` — is the first one's. A class is never a
19802
+ -- table, so none of these is an "array" or an "object".
19803
+ type TypeofNames = {
19804
+ Axes: Axes,
19805
+ BrickColor: BrickColor,
19806
+ CFrame: CFrame,
19807
+ CatalogSearchParams: CatalogSearchParams,
19808
+ Color3: Color3,
19809
+ ColorSequence: ColorSequence,
19810
+ ColorSequenceKeypoint: ColorSequenceKeypoint,
19811
+ Content: Content,
19812
+ DateTime: DateTime,
19813
+ DockWidgetPluginGuiInfo: DockWidgetPluginGuiInfo,
19814
+ Faces: Faces,
19815
+ FloatCurveKey: FloatCurveKey,
19816
+ Font: Font,
19817
+ InstanceHandle: InstanceHandle,
19818
+ NumberRange: NumberRange,
19819
+ NumberSequence: NumberSequence,
19820
+ NumberSequenceKeypoint: NumberSequenceKeypoint,
19821
+ OverlapParams: OverlapParams,
19822
+ Path2DControlPoint: Path2DControlPoint,
19823
+ PathWaypoint: PathWaypoint,
19824
+ PhysicalProperties: PhysicalProperties,
19825
+ RBXScriptConnection: RBXScriptConnection,
19826
+ Random: Random,
19827
+ Ray: Ray,
19828
+ RaycastParams: RaycastParams,
19829
+ Rect: Rect,
19830
+ Region3: Region3,
19831
+ Region3int16: Region3int16,
19832
+ RotationCurveKey: RotationCurveKey,
19833
+ Secret: Secret,
19834
+ SecurityCapabilities: SecurityCapabilities,
19835
+ SharedTable: SharedTable,
19836
+ TweenInfo: TweenInfo,
19837
+ UDim: UDim,
19838
+ UDim2: UDim2,
19839
+ User: User,
19840
+ ValueCurveKey: ValueCurveKey,
19841
+ Vector2: Vector2,
19842
+ Vector2int16: Vector2int16,
19843
+ Vector3: Vector3,
19844
+ Vector3int16: Vector3int16,
19845
+ Instance: Instance,
19846
+ Object: Object,
19847
+ EnumItem: EnumItem,
19848
+ Enum: Enum,
19849
+ Enums: Enums,
19850
+ }
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.1.0",
3
+ "version": "5.0.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": "^5.0.0"
19
22
  },
20
23
  "keywords": [
21
24
  "tilua",