Changing Warp from a regular to a strict table. Adding the ability to use Client and Server without calling fn(); (Like Buffer)

Why Strict Table instead Regular?
- Catching early syntax errors
- Preventing changes/replacements of keys in the table
- Better Error handling with link to Documentation

Why `metatable` instead `fn()` for `Server` and `Client`?
- Flexibility (now you can use ".Client" and ".Client()" without losing typing)
-  More convenient use - for me personally, it will be more convenient to use one API retrieval interface (including for Warp), as Buffer is currently retrieved directly, but Client and Server - not.

Also, I Fixed Type Error for line 6 (RunService get) and added some comments
This commit is contained in:
manee_too 2026-05-07 12:14:08 +07:00 committed by GitHub
parent a27067c8df
commit 5e972a7b9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,8 +1,9 @@
--!strict
--@EternityDev
local Remote = {}
if game.RunService:IsServer() then
if game:GetService("RunService"):IsServer() then
if not script:FindFirstChild("_repl") then
Instance.new("RemoteEvent", script).Name = "_repl"
end
@ -21,18 +22,24 @@ local Buffer = require("@self/Util/Buffer")
--[[
@class Remote
@client
client library of `Warp`, use it only on client
]]
Remote.Client = function()
Remote.Client = setmetatable(Client, {
__call = function()
return Client
end
end,
})
--[[
@class Remote
@server
server library of `Warp`, use it only on server
]]
Remote.Server = function()
Remote.Server = setmetatable(Server, {
__call = function()
return Server
end
end,
})
--[[
@class Remote
@ -41,4 +48,13 @@ end
]]
Remote.Buffer = Buffer
return Remote :: typeof(Remote)
-- making a strict table from `Warp` (Remote) - catching early errors and preventing changes/replacements of keys in the table
return setmetatable(Remote, {
__index = function(_self: any, key: any): never
error(`{key} is not valid member of Warp.\nPlease check documentation here: https://imezx.github.io/Warp/`)
end,
__newindex = function(_self: any, key: any, _value: any): never
error(`{key} is not valid member of Warp.\nPlease check documentation here: https://imezx.github.io/Warp/`)
end,
}) :: typeof(Remote) -- saving the typing