Skip to content

Conversation

@ColdMacaroni
Copy link
Contributor

These are all the docs in https://lunarmodules.github.io/luasocket/tcp.html, and some modifications to the existing docs related to tcp. The site only documents certain functions for specific types, like accept only exists for server sockets. I've tried to encode this in the types TCPSocketMaster, TCPSocketServer, and TCPSocketClient.

It does mean that the user needs to cast the master socket to either a server or client socket when appropriate :(, I've written down in the documentation when this should happen. I feel like this provides the most type safety with only a little friction for the user.

Creating a socket would look kinda like this (note the cast):

local my_sock, err = socket.tcp4()
if not my_sock then error(err) end

local ok, err = my_sock:bind("0.0.0.0", 8080)
if not ok then my_sock:close() error(err) end

local ok, err = my_sock:listen(32)
if not ok then my_sock:close() error(err) end

---@cast my_sock TCPSocketServer
local my_sock = my_sock

local client = my_sock:accept()
--- Etc...

Let me know what you think :D

PS: This should probably be a squash merge, I might have made too many commits. I'm happy to squash all of this into a single commit myself if it makes it easier for you :')

@Josef-Friedrich
Copy link
Collaborator

Thank you!

@Josef-Friedrich
Copy link
Collaborator

LuaLS/LLS-Addons#209

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants