build(types): luasocket

This commit is contained in:
Aire-One 2022-09-29 19:33:23 +02:00
parent b7f84d5744
commit 90c2aa4bc2
7 changed files with 369 additions and 0 deletions

45
types/ltn12.d.tl Normal file
View File

@ -0,0 +1,45 @@
local record ltn12
type Filter = function(string): string, string
type Sink = function(string, string): boolean, string
type Source = function(): string, string
type FancySink = function(string, string): boolean, string | FancySink
type FancySource = function(): string, string | FancySource
-- Docs just say returns a truthy value on success
-- Since this value should really only be
-- used to check for truthiness, any seems fine here
type Pump = function(Source, Sink): any, string
record filter
chain: function(Filter, Filter, ...: Filter): Filter
cycle: function(string, string, any): Filter
end
record pump
all: Pump
step: Pump
end
record sink
chain: function(Filter, Sink): Sink
error: function(string): Sink
file: function(FILE, string): Sink
null: function(): Sink
simplify: function(FancySink): Sink
table: function({string}): Sink, {string}
end
record source
cat: function(Source, ...: Source): Source
chain: function(Source, Filter): Source
empty: function(): Source
error: function(string): Source
file: function(FILE): Source
file: function(FILE, string): Source
simplify: function(FancySource): Source
string: function(string): Source
table: function({string}): Source, {string}
end
end
return ltn12

42
types/mime.d.tl Normal file
View File

@ -0,0 +1,42 @@
local ltn12 = require("ltn12")
local type Filter = ltn12.Filter
local record mime
normalize: function(): Filter
normalize: function(string): Filter
enum Encoding
"base64"
"quoted-printable"
end
enum Mode
"text"
"binary"
end
decode: function(Encoding): Filter
encode: function(Encoding, Mode): Filter
stuff: function(): Filter
wrap: function(string, integer): Filter
wrap: function(Encoding): Filter
b64: function(string, string): string, string
dot: function(integer, string): string, integer
eol: function(integer, string, string): string, integer
qp: function(string, string, string): string, string
qpwrp: function(integer, string, integer): string, integer
unb64: function(string, string): string, string
unqp: function(string, string): string, string
wrp: function(integer, string, integer): string, integer
end
return mime

158
types/socket.d.tl Normal file
View File

@ -0,0 +1,158 @@
local ltn12 = require("ltn12")
local Sink = ltn12.Sink
local Source = ltn12.Source
local record socket
record TCP
-- master methods
bind: function(TCP, string, integer)
connect: function(TCP, string, integer): integer, string
listen: function(TCP, integer): integer, string
-- client methods
getpeername: function(TCP): string, integer
enum TCPReceivePattern
"*l"
"*a"
end
enum TCPReceiveError
"closed"
"timeout"
end
receive: function(TCP, TCPReceivePattern|integer, string): string, TCPReceiveError
send: function(TCP, string, integer, integer): integer, string, integer
enum TCPShutdownMode
"both"
"send"
"receive"
end
shutdown: function(TCP, TCPShutdownMode): integer
-- server methods
accept: function(TCP): TCP, string
-- client and server methods
enum TCPOption
"keepalive"
"reuseaddr"
"tcp-nodelay"
end
enum TCPLinger
"linger"
end
record TCPLingerOption
on: boolean
timeout: integer
end
setoption: function(TCP, TCPOption): integer
setoption: function(TCP, TCPLinger, TCPLingerOption): integer
-- master, client, and server methods
close: function(TCP)
getsockname: function(TCP): string, integer
getstats: function(TCP): integer, integer, integer
setstats: function(TCP, integer, integer, integer): integer
enum TCPTimeoutMode
"b"
"t"
end
settimeout: function(TCP, integer, TCPTimeoutMode)
end
record UDP
close: function(UDP)
getpeername: function(UDP): string, integer
getsockname: function(UDP): string, integer
enum UDPTimeout
"timeout"
end
receive: function(UDP, integer): string, UDPTimeout
receivefrom: function(UDP, integer): string, string, integer, UDPTimeout
send: function(UDP, string): integer, string
sendto: function(UDP, string, string, integer): integer, string
setpeername: function(UDP, string, integer): integer, string
setsockname: function(UDP, string, integer): integer, string
enum UDPOptions
"dontroute"
"broadcast"
end
setoption: function(UDP, UDPOptions, boolean): integer, string
settimeout: function(UDP, integer)
end
tcp: function(): TCP, string
udp: function(): UDP, string
record dns
record DNSResolved
name: string
alias: {string}
ip: {string}
end
toip: function(): string
tohostname: function(string): string, DNSResolved|string
gethostname: function(string): string, DNSResolved|string
end
bind: function(string, integer, integer): TCP
connect: function(string, integer, string, integer): TCP
_DEBUG: boolean
newtry: function(function): function
protect: function(function): function
-- tagged records/Table Union types would be nice here,
-- as this should be {TCP|UDP}
-- but I imagine this should be fine for most uses
select: function({UDP}, {UDP}, integer): {UDP}, {UDP}, string
select: function({TCP}, {TCP}, integer): {TCP}, {TCP}, string
enum SinkMode
"http-chunked"
"close-when-done"
"keep-open"
end
sink: function(SinkMode, UDP): Sink
sink: function(SinkMode, TCP): Sink
skip: function(integer, ...: any): any...
sleep: function(integer)
enum SourceMode
"http-chunked"
"by-length"
"until-closed"
end
source: function(SourceMode, TCP, integer): Source
source: function(SourceMode, UDP, integer): Source
gettime: function(): integer
try: function(...: any): any...
_VERSION: string
end
return socket

39
types/socket/ftp.d.tl Normal file
View File

@ -0,0 +1,39 @@
local ltn12 = require("ltn12")
local type Pump = ltn12.Pump
local type Sink = ltn12.Sink
local record ftp
get: function(string): string, string
record FTPGetInfo
host: string
sink: Sink
argument: string
path: string
user: string
password: string
command: string
port: integer
type: string
step: Pump
create: function()
end
get: function(FTPGetInfo): integer, string
record FTPPutInfo
host: string
source: Sink -- yes, this is a sink
argument: string
path: string
user: string
password: string
command: string
port: integer
type: string
step: Pump
create: function()
end
put: function(string, string): integer, string
put: function(FTPPutInfo): integer, string
end
return ftp

28
types/socket/http.d.tl Normal file
View File

@ -0,0 +1,28 @@
local ltn12 = require("ltn12")
local type Pump = ltn12.Pump
local type Sink = ltn12.Sink
local type Source = ltn12.Source
local record http
request: function(string): string, integer|string, string, string
request: function(string, string): string, integer|string, string, string
record HTTPRequest
url: string
sink: Sink
method: string
headers: {string:string}
source: Source
step: Pump
proxy: string
redirect: boolean
create: function
end
request: function(HTTPRequest): string, integer|string, string, string
PORT: integer
PROXY: string
TIMEOUT: integer
USERAGENT: string
end
return http

32
types/socket/smtp.d.tl Normal file
View File

@ -0,0 +1,32 @@
local ltn12 = require("ltn12")
local type Pump = ltn12.Pump
local type Source = ltn12.Source
local record smtp
record Message
headers: {string:string}
body: Source | string | MultipartMessage
end
record MultipartMessage
{Message}
preamble: string
epilogue: string
end
message: function(Message): Source
record SMTPSendFormat
from: string
rcpt: string | {string}
source: Source
user: string
password: string
server: string
port: integer
domain: string
step: Pump
create: function
end
send: function(SMTPSendFormat): integer, string
end
return smtp

25
types/socket/url.d.tl Normal file
View File

@ -0,0 +1,25 @@
local record url
record ParsedUrl
url: string
scheme: string
authority: string
path: string
params: string
query: string
fragment: string
userinfo: string
host: string
port: string
user: string
password: string
end
absolute: function(string, string): string
build: function(ParsedUrl): string
build_path: function({string}, any): string
escape: function(string): string
parse: function(string, table): ParsedUrl
parse_path: function(string): {string}
unescape: function(string): string
end
return url