From 5e972a7b9c4b36b97b632d45d03ffe036c3c2c24 Mon Sep 17 00:00:00 2001 From: manee_too Date: Thu, 7 May 2026 12:14:08 +0700 Subject: [PATCH] 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 --- src/init.luau | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/init.luau b/src/init.luau index b5d0989..b819740 100644 --- a/src/init.luau +++ b/src/init.luau @@ -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() - return Client -end +Remote.Client = setmetatable(Client, { + __call = function() + return Client + end, +}) --[[ @class Remote @server + server library of `Warp`, use it only on server ]] -Remote.Server = function() - return Server -end +Remote.Server = setmetatable(Server, { + __call = function() + return Server + 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