Skip to content

Commit 17983e4

Browse files
full type definitions for all lute std (#351)
1 parent a73d443 commit 17983e4

File tree

8 files changed

+244
-10
lines changed

8 files changed

+244
-10
lines changed

definitions/crypto.luau

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@ crypto.hash = {
99
sha512 = {} :: Hash<"sha512">,
1010
blake2b256 = {} :: Hash<"blake2b256">,
1111
}
12+
crypto.password = {}
1213

1314
function crypto.digest(hash: Hash<any>, message: string | buffer): buffer
1415
error("not implemented")
1516
end
1617

18+
function crypto.password.hash(password: string): buffer
19+
error("not implemented")
20+
end
21+
22+
function crypto.password.verify(hash: buffer, password: string): boolean
23+
error("not implemented")
24+
end
25+
1726
return crypto

definitions/fs.luau

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type FileHandle = {
66
}
77

88
export type FileType = "file" | "dir" | "link" | "fifo" | "socket" | "char" | "block" | "unknown"
9+
export type HandleMode = "r" | "w" | "x" | "a" | "r+" | "w+" | "x+" | "a+"
910

1011
export type DirectoryEntry = {
1112
name: string,
@@ -21,7 +22,7 @@ export type WatchEvent = {
2122
rename: boolean,
2223
}
2324

24-
function fs.open(path: string): FileHandle
25+
function fs.open(path: string, mode: HandleMode?): FileHandle
2526
error("not implemented")
2627
end
2728

definitions/net.luau

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
11
local net = {}
22

3-
export type metadata = {
3+
export type Metadata = {
44
method: string?,
55
body: string?,
66
headers: { [string]: string }?,
77
}
88

9-
export type request = {
9+
export type Request = {
1010
body: string,
1111
headers: { [string]: string },
1212
status: number,
1313
ok: boolean,
1414
}
1515

16-
function net.request(url: string, metadata: metadata?): request
16+
function net.request(url: string, metadata: Metadata?): Request
1717
error("not implemented")
1818
end
1919

20-
export type handler = (...any) -> ...any
20+
export type ReceivedRequest = {
21+
method: string,
22+
path: string,
23+
body: string,
24+
query: { [string]: string },
25+
headers: { [string]: string },
26+
}
27+
28+
export type ServerResponse = string | {
29+
status: number?,
30+
body: string?,
31+
headers: { [string]: string }?,
32+
}
33+
34+
export type Handler = (request: ReceivedRequest) -> ServerResponse
2135

22-
export type configuration = {
36+
export type Configuration = {
2337
hostname: string?,
2438
port: number?,
2539
reuseport: boolean?,
26-
tls: { cert_file_name: string, key_file_name: string, passphrase: string?, ca_file_name: string? },
27-
handler: handler,
40+
tls: { cert_file_name: string, key_file_name: string, passphrase: string?, ca_file_name: string? }?,
41+
handler: Handler,
2842
}
2943

30-
function net.serve(config: configuration | handler)
44+
function net.serve(config: Handler | Configuration)
3145
error("not implemented")
3246
end
3347

definitions/process.luau

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export type StdioKind = "default" | "inherit" | "none" | ""
2+
3+
export type ProcessRunOptions = {
4+
shell: (string | boolean)?,
5+
cwd: string?,
6+
stdio: StdioKind?,
7+
8+
env: { [string]: string }?,
9+
}
10+
11+
export type ProcessResult = {
12+
stdout: string,
13+
stderr: string,
14+
15+
ok: boolean,
16+
exitcode: number,
17+
signal: string?,
18+
}
19+
20+
local process = {}
21+
22+
function process.homedir(): string
23+
error("not implemented")
24+
end
25+
26+
function process.cwd(): string
27+
error("not implemented")
28+
end
29+
30+
function process.run(args: string | { string }, options: ProcessRunOptions?): ProcessResult
31+
error("not implemented")
32+
end
33+
34+
return process

definitions/system.luau

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export type CpuInfo = {
2+
model: string,
3+
speed: number,
4+
5+
times: {
6+
sys: number,
7+
idle: number,
8+
irq: number,
9+
nice: number,
10+
user: number,
11+
},
12+
}
13+
14+
local system = {}
15+
16+
function system.threadcount(): number
17+
error("unimplemented")
18+
end
19+
20+
function system.hostname(): string
21+
error("unimplemented")
22+
end
23+
24+
function system.totalmemory(): number
25+
error("unimplemented")
26+
end
27+
28+
function system.freememory(): number
29+
error("unimplemented")
30+
end
31+
32+
function system.uptime(): number
33+
error("unimplemented")
34+
end
35+
36+
function system.cpus(): { CpuInfo }
37+
error("unimplemented")
38+
end
39+
40+
system.os = "" :: string
41+
system.arch = "" :: string
42+
43+
return system

definitions/task.luau

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
local time = require("./time")
2+
3+
local task = {}
4+
5+
function task.defer()
6+
error("unimplemented")
7+
end
8+
9+
function task.wait(dur: (number | time.Duration)?)
10+
error("unimplemented")
11+
end
12+
13+
function task.spawn<T..., U...>(routine: ((T...) -> U...) | thread, ...: T...)
14+
error("unimplemented")
15+
end
16+
17+
function task.resume(thread: thread)
18+
error("unimplemented")
19+
end
20+
21+
return task

definitions/time.luau

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
local time = {}
2+
local duration = {}
3+
local duration_ops = {}
4+
local instant = {}
5+
6+
function time.now(): Instant
7+
error("not implemented")
8+
end
9+
10+
function time.since(instant: Instant): number
11+
error("not implemented")
12+
end
13+
14+
function duration.nanoseconds(nanoseconds: number): Duration
15+
error("not implemented")
16+
end
17+
18+
function duration.microseconds(microseconds: number): Duration
19+
error("not implemented")
20+
end
21+
22+
function duration.milliseconds(milliseconds: number): Duration
23+
error("not implemented")
24+
end
25+
26+
function duration.seconds(seconds: number): Duration
27+
error("not implemented")
28+
end
29+
30+
function duration.minutes(minutes: number): Duration
31+
error("not implemented")
32+
end
33+
34+
function duration.hours(hours: number): Duration
35+
error("not implemented")
36+
end
37+
38+
function duration.days(days: number): Duration
39+
error("not implemented")
40+
end
41+
42+
function duration.weeks(weeks: number): Duration
43+
error("not implemented")
44+
end
45+
46+
function instant.elapsed(self: Instant): number
47+
error("not implemented")
48+
end
49+
50+
function duration_ops.tonanoseconds(self: Duration): number
51+
error("not implemented")
52+
end
53+
54+
function duration_ops.tomicroseconds(self: Duration): number
55+
error("not implemented")
56+
end
57+
58+
function duration_ops.tomilliseconds(self: Duration): number
59+
error("not implemented")
60+
end
61+
62+
function duration_ops.toseconds(self: Duration): number
63+
error("not implemented")
64+
end
65+
66+
function duration_ops.tominutes(self: Duration): number
67+
error("not implemented")
68+
end
69+
70+
function duration_ops.tohours(self: Duration): number
71+
error("not implemented")
72+
end
73+
74+
function duration_ops.todays(self: Duration): number
75+
error("not implemented")
76+
end
77+
78+
function duration_ops.toweeks(self: Duration): number
79+
error("not implemented")
80+
end
81+
82+
function duration_ops.subsecnanos(self: Duration): number
83+
error("not implemented")
84+
end
85+
86+
function duration_ops.subsecmicros(self: Duration): number
87+
error("not implemented")
88+
end
89+
90+
function duration_ops.subsecmillis(self: Duration): number
91+
error("not implemented")
92+
end
93+
94+
type Frozen = typeof(table.freeze({}))
95+
export type Duration = setmetatable<Frozen, {
96+
read __metatable: "The metatable is locked!",
97+
read __index: typeof(table.freeze(duration_ops)),
98+
read __add: (Duration, Duration) -> Duration,
99+
read __sub: (Duration, Duration) -> Duration,
100+
read __eq: (Duration, Duration) -> boolean,
101+
read __lt: (Duration, Duration) -> boolean,
102+
read __le: (Duration, Duration) -> boolean,
103+
}>
104+
105+
export type Instant = setmetatable<Frozen, {
106+
read __metatable: "The metatable is locked!",
107+
read __index: typeof(table.freeze(instant)),
108+
read __sub: (Instant, Instant) -> Duration,
109+
}>
110+
111+
time.duration = duration
112+
return time

definitions/vm.luau

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local vm = {}
22

3-
function vm.create(path: string): any
3+
function vm.create(path: string): { [any]: any }
44
error("not implemented")
55
end
66

0 commit comments

Comments
 (0)