Skip to content

Commit 7dfbbd8

Browse files
authored
Add a few type definitions that I had to write today for the sake of demoing things. (#302)
We're working towards #60 by adding type definitions for `@lute/crypto`, @lute/vm`, and `@lute/net`, plus two missing functions from the `@lute/luau` definitions. These came out of making a short demo video of Lute for internal use.
1 parent e9fdcd7 commit 7dfbbd8

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

definitions/crypto.luau

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local crypto = {}
2+
3+
export type Hash<T> = { __hash: T }
4+
5+
crypto.hash = {
6+
md5 = {} :: Hash<"md5">,
7+
sha1 = {} :: Hash<"sha1">,
8+
sha256 = {} :: Hash<"sha256">,
9+
sha512 = {} :: Hash<"sha512">,
10+
blake2b256 = {} :: Hash<"blake2b256">,
11+
}
12+
13+
function crypto.digest(hash: Hash<any>, message: string | buffer): buffer
14+
error("not implemented")
15+
end
16+
17+
return crypto

definitions/luau.luau

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,4 +563,14 @@ function luau.parseexpr(source: string): AstExpr
563563
error("not implemented")
564564
end
565565

566+
export type Bytecode = { bytecode: string }
567+
568+
function luau.compile(source: string): Bytecode
569+
error("not implemented")
570+
end
571+
572+
function luau.load(bytecode: Bytecode): () -> ...any
573+
error("not implemented")
574+
end
575+
566576
return luau

definitions/net.luau

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
local net = {}
2+
3+
export type metadata = {
4+
method: string?,
5+
body: string?,
6+
headers: { [string]: string }?,
7+
}
8+
9+
export type request = {
10+
body: string,
11+
headers: { [string]: string },
12+
status: number,
13+
ok: boolean,
14+
}
15+
16+
function net.request(url: string, metadata: metadata?): request
17+
error("not implemented")
18+
end
19+
20+
export type handler = (...any) -> ...any
21+
22+
export type configuration = {
23+
hostname: string?,
24+
port: number?,
25+
reuseport: boolean?,
26+
tls: { cert_file_name: string, key_file_name: string, passphrase: string?, ca_file_name: string? },
27+
handler: handler,
28+
}
29+
30+
function net.serve(config: configuration | handler)
31+
error("not implemented")
32+
end
33+
34+
return net

definitions/vm.luau

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local vm = {}
2+
3+
function vm.create(path: string): any
4+
error("not implemented")
5+
end
6+
7+
return vm

0 commit comments

Comments
 (0)