Compare commits

..

No commits in common. "bccb40e8e7d5c3ea020b972fa1d7da862bbe3345" and "5a786ba8f18d0735ec6e69ca52c80b77cfc13e60" have entirely different histories.

4 changed files with 0 additions and 55 deletions

View file

@ -1,3 +0,0 @@
{
"deno.enable": true
}

View file

@ -1,38 +0,0 @@
#!/bin/env -S deno run --allow-read --allow-net
async function main() {
const [program_path] = Deno.args;
if (program_path === undefined) fail_with("Usage: host.ts <program_path>");
const port = 1728;
const server = Deno.listen({ port });
console.log("listening on port", port);
for await (const connection of server) handle(connection, program_path);
}
async function handle(connection: Deno.TcpConn, program_path: string) {
console.log("serving");
const file = await try_else(
() => Deno.open(program_path, { read: true }),
() => fail_with("Program at", program_path, "does not exists"),
);
await try_(() => file.readable.pipeTo(connection.writable));
}
function fail_with(...message: string[]) {
console.error(...message);
return Deno.exit(1);
}
async function try_else<T>(operation: () => T | Promise<T>, on_error: (error: unknown) => T | Promise<T>) {
try {
return await operation();
} catch (error) {
return await on_error(error);
}
}
async function try_<T>(operation: () => T | Promise<T>) {
return await try_else(operation, () => null);
}
if (import.meta.main) await main();

View file

@ -1,8 +0,0 @@
local arg1, arg2, arg3 = ...
local function main()
print("arg1", arg1, "arg2", arg2, "arg3", arg3)
local file = fs.open()
end
main()

View file

@ -1,6 +0,0 @@
{
"fmt": {
"useTabs": true,
"lineWidth": 120
}
}