aboutsummaryrefslogtreecommitdiff
path: root/library/lullaby/net.lua
diff options
context:
space:
mode:
authoramelia squires <[email protected]>2025-03-31 13:21:27 -0500
committeramelia squires <[email protected]>2025-03-31 13:21:27 -0500
commit876e28e4dc4a6f2c19dc2523f5db78fa6e4a16a9 (patch)
treed1adb6a4e3cdf9ae3c11920ac98d4ed54bae8cca /library/lullaby/net.lua
parent19cb409b0aee4b8605977644d8941460c02cdf80 (diff)
type definitions
Diffstat (limited to 'library/lullaby/net.lua')
-rw-r--r--library/lullaby/net.lua166
1 files changed, 166 insertions, 0 deletions
diff --git a/library/lullaby/net.lua b/library/lullaby/net.lua
new file mode 100644
index 0000000..3f9abdc
--- /dev/null
+++ b/library/lullaby/net.lua
@@ -0,0 +1,166 @@
+---@meta
+
+---@class net
+local net = {}
+
+---@class server-table
+local server_table = {}
+
+---@class res-table
+local res_table = {}
+
+---sends value to client and closes socket
+---@param T res-table
+---@param value string
+function res_table.send(T, value) end
+
+---autosets Content-Type and sends contents of file to client and closes socket
+---@param T res-table
+---@param value string
+function res_table.sendfile(T, value) end
+
+---sends value to client and doesn't close the socket
+---@param T res-table
+---@param value string
+function res_table.write(T, value) end
+
+---closes socket
+---@param T res-table
+function res_table.close(T) end
+
+---prevents calling any other selected routes
+---@param T res-table
+function res_table.stop(T) end
+
+---key value table containing header values to be sent
+res_table.header = {}
+
+---@class req-table
+local req_table = {}
+
+---"roll" the request forward
+---@param T req-table
+---@param bytes integer | nil
+function req_table.roll(T, bytes) end
+
+---list of parameters in route
+req_table.parameters = {}
+
+---@deprecated
+req_table.client_fd = 0
+
+---@deprecated
+req_table._bytes = 0
+
+---@type integer
+req_table.ip = 0
+
+---@type string
+req_table.Body = ""
+
+---@type any|nil
+req_table.files = {}
+
+---@type any|nil
+req_table.cookies = {}
+
+
+---@param T server-table
+---@param route string
+---@param callback fun(res: res-table, req: req-table)
+function server_table.GET(T, route, callback) end
+
+---@param T server-table
+---@param route string
+---@param callback fun(res: res-table, req: req-table)
+function server_table.HEAD(T, route, callback) end
+
+---@param T server-table
+---@param route string
+---@param callback fun(res: res-table, req: req-table)
+function server_table.POST(T, route, callback) end
+
+---@param T server-table
+---@param route string
+---@param callback fun(res: res-table, req: req-table)
+function server_table.PUT(T, route, callback) end
+
+---@param T server-table
+---@param route string
+---@param callback fun(res: res-table, req: req-table)
+function server_table.DELETE(T, route, callback) end
+
+---@param T server-table
+---@param route string
+---@param callback fun(res: res-table, req: req-table)
+function server_table.CONNECT(T, route, callback) end
+
+---@param T server-table
+---@param route string
+---@param callback fun(res: res-table, req: req-table)
+function server_table.OPTIONS(T, route, callback) end
+
+---@param T server-table
+---@param route string
+---@param callback fun(res: res-table, req: req-table)
+function server_table.TRACE(T, route, callback) end
+
+---@param T server-table
+---@param route string
+---@param callback fun(res: res-table, req: req-table)
+function server_table.PATCH(T, route, callback) end
+
+---@param T server-table
+---@param route string
+---@param callback fun(res: res-table, req: req-table)
+function server_table.all(T, route, callback) end
+
+---@param server server-table
+local function listen_callback(server) end
+
+---@param callback fun(server: server-table)
+---@param port integer
+function net.listen(callback, port) end
+
+---creates an https request
+---@param url string
+---@param value string | nil
+---@param header table<string, string> | nil
+---@param request string | nil
+---@return table<string, string> | error
+function net.srequest(url, value, header, request) end
+
+---@class wss-table
+local wss = {}
+
+---@class wss-read
+local wss_read = {}
+
+---@type string
+wss_read.content = ""
+
+---@type integer
+wss_read.opcode = 0
+
+---reads oldest unread frame from server
+---@param T wss-table
+---@return wss-read | error
+function wss.read(T) end
+
+---sents data frame to server
+---@param T wss-table
+---@param data string
+---@return nil | error
+function wss.write(T, data) end
+
+---calls gc early
+---@param T wss-table
+---@return nil
+function wss.close(T) end
+
+---creates a wss connection
+---@param url string
+---@return wss-table | error
+function net.wss(url) end
+
+return net