mirror of
https://github.com/imezx/Warp.git
synced 2026-06-02 12:18:32 +00:00
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:
parent
a27067c8df
commit
5e972a7b9c
1 changed files with 24 additions and 8 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
--!strict
|
--!strict
|
||||||
--@EternityDev
|
--@EternityDev
|
||||||
|
|
||||||
local Remote = {}
|
local Remote = {}
|
||||||
|
|
||||||
if game.RunService:IsServer() then
|
if game:GetService("RunService"):IsServer() then
|
||||||
if not script:FindFirstChild("_repl") then
|
if not script:FindFirstChild("_repl") then
|
||||||
Instance.new("RemoteEvent", script).Name = "_repl"
|
Instance.new("RemoteEvent", script).Name = "_repl"
|
||||||
end
|
end
|
||||||
|
|
@ -21,18 +22,24 @@ local Buffer = require("@self/Util/Buffer")
|
||||||
--[[
|
--[[
|
||||||
@class Remote
|
@class Remote
|
||||||
@client
|
@client
|
||||||
|
client library of `Warp`, use it only on client
|
||||||
]]
|
]]
|
||||||
Remote.Client = function()
|
Remote.Client = setmetatable(Client, {
|
||||||
|
__call = function()
|
||||||
return Client
|
return Client
|
||||||
end
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
@class Remote
|
@class Remote
|
||||||
@server
|
@server
|
||||||
|
server library of `Warp`, use it only on server
|
||||||
]]
|
]]
|
||||||
Remote.Server = function()
|
Remote.Server = setmetatable(Server, {
|
||||||
|
__call = function()
|
||||||
return Server
|
return Server
|
||||||
end
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
@class Remote
|
@class Remote
|
||||||
|
|
@ -41,4 +48,13 @@ end
|
||||||
]]
|
]]
|
||||||
Remote.Buffer = Buffer
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue