More typedef improvements for roblox builtin

This commit is contained in:
Filip Tibell 2023-05-20 19:49:37 +02:00
parent f1c62245da
commit 73efb5fc99
No known key found for this signature in database
24 changed files with 49 additions and 39 deletions

View file

@ -2,7 +2,8 @@ type InstanceProperties = {
Parent: Instance?, Parent: Instance?,
ClassName: string, ClassName: string,
Name: string, Name: string,
-- FIXME: This breaks intellisense, but we need some way to access instance properties... -- FIXME: This breaks intellisense, but we need some way to access
-- instance properties without casting the entire instance to any...
-- [string]: any, -- [string]: any,
} }
@ -218,4 +219,8 @@ return {
getAuthCookie = function(raw: boolean?): string? getAuthCookie = function(raw: boolean?): string?
return nil :: any return nil :: any
end, end,
-- TODO: Make typedefs for all of the datatypes as well...
Instance = (nil :: any) :: {
new: ((className: "DataModel") -> DataModel) & ((className: string) -> Instance),
},
} }

View file

@ -1,5 +1,5 @@
local fs = require("@lune/fs") local fs = require("@lune/fs")
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local modelDirs = {} local modelDirs = {}
for _, dirName in fs.readDir("tests/roblox/rbx-test-files/places") do for _, dirName in fs.readDir("tests/roblox/rbx-test-files/places") do

View file

@ -1,5 +1,5 @@
local fs = require("@lune/fs") local fs = require("@lune/fs")
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local placeDirs = {} local placeDirs = {}
for _, dirName in fs.readDir("tests/roblox/rbx-test-files/places") do for _, dirName in fs.readDir("tests/roblox/rbx-test-files/places") do

View file

@ -1,5 +1,5 @@
local fs = require("@lune/fs") local fs = require("@lune/fs")
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local instances = { local instances = {

View file

@ -1,5 +1,5 @@
local fs = require("@lune/fs") local fs = require("@lune/fs")
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local game = Instance.new("DataModel") local game = Instance.new("DataModel")

View file

@ -1,18 +1,19 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local game = Instance.new("DataModel") local game = Instance.new("DataModel")
-- Workspace should always exist as a "Workspace" property, or be created when accessed -- Workspace should always exist as a "Workspace" property, or be created when accessed
assert(game.Workspace ~= nil) local workspace = (game :: any).Workspace
assert(game.Workspace:IsA("Workspace")) assert(workspace ~= nil)
assert(game.Workspace == game:FindFirstChildOfClass("Workspace")) assert(workspace:IsA("Workspace"))
assert(workspace == game:FindFirstChildOfClass("Workspace"))
-- GetService and FindService should work, GetService should create services that don't exist -- GetService and FindService should work, GetService should create services that don't exist
assert(game:FindService("CSGDictionaryService") == nil) assert(game:FindService("CSGDictionaryService") == nil)
assert(game:GetService("CSGDictionaryService") ~= nil) assert(game:GetService("CSGDictionaryService"))
assert(game:FindService("CSGDictionaryService") ~= nil) assert(game:FindService("CSGDictionaryService") ~= nil)
-- Service names should be strict and not allow weird characters or substrings -- Service names should be strict and not allow weird characters or substrings

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local game = Instance.new("DataModel") local game = Instance.new("DataModel")
@ -6,12 +6,14 @@ local workspace = game:GetService("Workspace")
-- Terrain should always exist as a "Terrain" property, or be created when accessed -- Terrain should always exist as a "Terrain" property, or be created when accessed
assert(workspace.Terrain ~= nil) local terrain = (workspace :: any).Terrain
assert(workspace.Terrain:IsA("Terrain")) assert(terrain ~= nil)
assert(workspace.Terrain == workspace:FindFirstChildOfClass("Terrain")) assert(terrain:IsA("Terrain"))
assert(terrain == workspace:FindFirstChildOfClass("Terrain"))
-- Camera should always exist as a "CurrentCamera" property, or be created when accessed -- Camera should always exist as a "CurrentCamera" property, or be created when accessed
assert(workspace.CurrentCamera ~= nil) local camera = (workspace :: any).CurrentCamera
assert(workspace.CurrentCamera:IsA("Camera")) assert(camera ~= nil)
assert(workspace.CurrentCamera == workspace:FindFirstChildOfClass("Camera")) assert(camera:IsA("Camera"))
assert(camera == workspace:FindFirstChildOfClass("Camera"))

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local root = Instance.new("Model") local root = Instance.new("Model")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local root = Instance.new("Model") local root = Instance.new("Model")
@ -7,9 +7,9 @@ local objValue1 = Instance.new("ObjectValue")
local objValue2 = Instance.new("ObjectValue") local objValue2 = Instance.new("ObjectValue")
objValue1.Name = "ObjectValue1" objValue1.Name = "ObjectValue1"
objValue2.Name = "ObjectValue2" objValue2.Name = "ObjectValue2";
objValue1.Value = root (objValue1 :: any).Value = root;
objValue2.Value = child (objValue2 :: any).Value = child
objValue1.Parent = child objValue1.Parent = child
objValue2.Parent = child objValue2.Parent = child
child.Parent = root child.Parent = root

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local root = Instance.new("Folder") local root = Instance.new("Folder")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local root = Instance.new("Folder") local root = Instance.new("Folder")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local root = Instance.new("Folder") local root = Instance.new("Folder")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local root = Instance.new("Folder") local root = Instance.new("Folder")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local root = Instance.new("Folder") local root = Instance.new("Folder")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local root = Instance.new("Folder") local root = Instance.new("Folder")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local root = Instance.new("Folder") local root = Instance.new("Folder")

View file

@ -1,5 +1,5 @@
local fs = require("@lune/fs") local fs = require("@lune/fs")
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local modelFile = fs.readFile("tests/roblox/rbx-test-files/models/three-nested-folders/binary.rbxm") local modelFile = fs.readFile("tests/roblox/rbx-test-files/models/three-nested-folders/binary.rbxm")

View file

@ -1,5 +1,5 @@
local fs = require("@lune/fs") local fs = require("@lune/fs")
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local modelFile = fs.readFile("tests/roblox/rbx-test-files/models/three-nested-folders/binary.rbxm") local modelFile = fs.readFile("tests/roblox/rbx-test-files/models/three-nested-folders/binary.rbxm")

View file

@ -1,11 +1,13 @@
local fs = require("@lune/fs") local fs = require("@lune/fs")
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local modelFile = fs.readFile("tests/roblox/rbx-test-files/models/three-nested-folders/binary.rbxm") local modelFile = fs.readFile("tests/roblox/rbx-test-files/models/three-nested-folders/binary.rbxm")
local model = roblox.deserializeModel(modelFile)[1] local model = roblox.deserializeModel(modelFile)[1]
local child = model:FindFirstChild("Parent") local child = model:FindFirstChild("Parent")
assert(child ~= nil)
local descendant = child:FindFirstChild("Child") local descendant = child:FindFirstChild("Child")
assert(descendant ~= nil)
assert(descendant:GetFullName() == "Grandparent.Parent.Child") assert(descendant:GetFullName() == "Grandparent.Parent.Child")
assert(child:GetFullName() == "Grandparent.Parent") assert(child:GetFullName() == "Grandparent.Parent")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local part = Instance.new("Part") local part = Instance.new("Part")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local root = Instance.new("Folder") local root = Instance.new("Folder")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local root = Instance.new("Folder") local root = Instance.new("Folder")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
-- Should not allow creating unknown classes -- Should not allow creating unknown classes
@ -33,7 +33,7 @@ assert(model.Parent == nil)
-- Parenting and indexing should work -- Parenting and indexing should work
model.Parent = folder model.Parent = folder
assert(model.Parent == folder) assert(model.Parent == folder)
assert(folder.Model == model) assert((folder :: any).Model == model)
-- Parenting to nil should work -- Parenting to nil should work
model.Parent = nil model.Parent = nil
@ -43,6 +43,6 @@ assert(model.Parent == nil)
model.Name = "MyCoolModel" model.Name = "MyCoolModel"
assert(model.Name == "MyCoolModel") assert(model.Name == "MyCoolModel")
assert(not pcall(function() assert(not pcall(function()
model.Name = nil model.Name = nil :: any
end)) end))
assert(model.Name == "MyCoolModel") assert(model.Name == "MyCoolModel")

View file

@ -1,4 +1,4 @@
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox")
local Instance = roblox.Instance local Instance = roblox.Instance
local model = Instance.new("Model") local model = Instance.new("Model")