tools: add html-generator tools to automatically generate
application.html
This commit is contained in:
parent
8d4c51738e
commit
19fb2e8ebd
2 changed files with 36 additions and 10 deletions
26
tools/html-generator.zig
Normal file
26
tools/html-generator.zig
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
const source = @embedFile("../www/template.html");
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
|
const allocator = gpa.allocator();
|
||||||
|
defer _ = gpa.deinit();
|
||||||
|
|
||||||
|
const args = try std.process.argsAlloc(allocator);
|
||||||
|
defer std.process.argsFree(allocator, args);
|
||||||
|
|
||||||
|
if (args.len < 3) {
|
||||||
|
std.debug.print("Usage: html-generator <output-name> <application-name>\n", .{});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const output_name = args[1];
|
||||||
|
const application_name = args[2];
|
||||||
|
|
||||||
|
const file = try std.fs.cwd().createFile(output_name, std.fs.File.CreateFlags{});
|
||||||
|
defer file.close();
|
||||||
|
|
||||||
|
const writer = file.writer();
|
||||||
|
try std.fmt.format(writer, source, .{application_name});
|
||||||
|
}
|
||||||
|
|
@ -3,35 +3,35 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<style>
|
<style>
|
||||||
canvas {
|
canvas {{
|
||||||
border: 1px solid;
|
border: 1px solid;
|
||||||
}
|
}}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { mach } from "./mach.js";
|
import {{ mach }} from "./mach.js";
|
||||||
|
|
||||||
let imports = {
|
let imports = {{
|
||||||
env: mach,
|
env: mach,
|
||||||
};
|
}};
|
||||||
|
|
||||||
fetch("application.wasm")
|
fetch("{s}.wasm")
|
||||||
.then(response => response.arrayBuffer())
|
.then(response => response.arrayBuffer())
|
||||||
.then(buffer => WebAssembly.instantiate(buffer, imports))
|
.then(buffer => WebAssembly.instantiate(buffer, imports))
|
||||||
.then(results => results.instance)
|
.then(results => results.instance)
|
||||||
.then(instance => {
|
.then(instance => {{
|
||||||
mach.init(instance);
|
mach.init(instance);
|
||||||
instance.exports.wasmInit();
|
instance.exports.wasmInit();
|
||||||
|
|
||||||
let update = function() {
|
let update = function() {{
|
||||||
const r = instance.exports.wasmUpdate();
|
const r = instance.exports.wasmUpdate();
|
||||||
if (r) requestAnimationFrame(update)
|
if (r) requestAnimationFrame(update)
|
||||||
else instance.exports.wasmDeinit();
|
else instance.exports.wasmDeinit();
|
||||||
};
|
}};
|
||||||
|
|
||||||
requestAnimationFrame(update);
|
requestAnimationFrame(update);
|
||||||
})
|
}})
|
||||||
.catch(err => console.error(err));
|
.catch(err => console.error(err));
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue