I’m writing my own framework based off of how the roblox engine does their framework. Basically game is a Roblox Global that is a table that contains Libraries and functions such as :GetService() or time().
I want mine to function similarly, where I can do something along the lines of Framework.time() or Framework:GetService(), however i’ve run into a problem and that’s intellisense. I can’t figure out how to get my properties, functions, and variables to show up when writing.
I don’t want to have to require every module I’ll need to use, rather just require the main framework module and reference from there. Is there a way to do this or am I doomed to require every module I need?
local RunService = game:GetService("RunService")
local Framework = {}
local SERVICES = {}
local PACKAGE = script.Parent
local CLASSES: Folder = PACKAGE:FindFirstChild("Classes")
local DATA_TYPES: Folder = PACKAGE:FindFirstChild("DataTypes")
local ENUMS: Folder = PACKAGE:FindFirstChild("Enums")
local LIBRARIES: Folder = PACKAGE:FindFirstChild("Libraries")
Framework.Started = false
function Framework:Init()
-- Init DataTypes
for _, dataType in pairs(DATA_TYPES:GetChildren()) do
Framework[dataType.Name] = require(dataType)
end
-- Init Enums
for _, enum in pairs(ENUMS:GetChildren()) do
Framework[enum.Name] = require(enum)
end
-- Init Libraries
for _, library in pairs(LIBRARIES:GetChildren()) do
Framework[library.Name] = require(library)
end
-- Init Classes
for _, class in pairs(CLASSES:GetChildren()) do
local _class = require(class)
if table.find(_class.Tags, "Service") then
SERVICES[class.Name] = _class
end
end
end
function Framework:GetService(serviceName: string): {any}
assert(Framework.Started, "Cannot call GetService until framework has been started")
assert(type(serviceName) == "string", `ServiceName must be a string; got {type(serviceName)}`)
return assert(SERVICES[serviceName], `Could not find service "{serviceName}"`)
end
function Framework:GetServices(): {any}
assert(Framework.Started, "Cannot call GetServices until framework has been started")
return SERVICES
end
return Framework