Skip to content

Commit d146584

Browse files
committed
Add more templates.
1 parent cb9822d commit d146584

File tree

9 files changed

+81
-12
lines changed

9 files changed

+81
-12
lines changed

templates/empty_c/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Empty C Project

templates/empty_c/build.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
gulp.task("build", async () => {
2+
const data = await Service.compileFile(project.getFile("src/main.c"), "c", "wasm", "-g -O3");
3+
const outWasm = project.newFile("out/main.wasm", "wasm");
4+
outWasm.setData(data);
5+
const result = await Service.disassembleWasm(data);
6+
outWasm.buffer.setValue(result);
7+
});
8+
9+
gulp.task("default", ["build"], async () => {});

templates/empty_c/src/main.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#define WASM_EXPORT __attribute__((visibility("default")))
2+
3+
WASM_EXPORT
4+
int main() {
5+
return 42;
6+
}

templates/empty_c/src/main.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html>
2+
3+
<body>
4+
<style>
5+
body {
6+
background-color: rgb(255, 255, 255);
7+
}
8+
</style>
9+
<script src="src/main.js"></script>
10+
<span id="container" />
11+
</body>
12+
13+
</html>

templates/empty_c/src/main.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fetch(getFileURL('out/main.wasm')).then(response =>
2+
response.arrayBuffer()
3+
).then(bytes => WebAssembly.instantiate(bytes)).then(results => {
4+
instance = results.instance;
5+
document.getElementById("container").innerText = instance.exports.main();
6+
});

templates/hello_world_c/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Hello World in C
2+
A C project that prints "Hello World" using a minimal POSIX API.

templates/hello_world_c/build.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
gulp.task("build", async () => {
2+
const data = await Service.compileFile(project.getFile("src/main.c"), "c", "wasm", "-g -O3");
3+
const outWasm = project.newFile("out/main.wasm", "wasm");
4+
outWasm.setData(data);
5+
const result = await Service.disassembleWasm(data);
6+
outWasm.buffer.setValue(result);
7+
});
8+
9+
gulp.task("default", ["build"], async () => {});

templates/templates.js

+32-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
11
[{
2+
"name": "Empty C Project",
3+
"description": `# Empty C Project
4+
`,
5+
"icon": "svg/file_type_c.svg",
6+
"project": {
7+
"name": "Project",
8+
"directory": "empty_c",
9+
"children": [{
10+
"name": "src",
11+
"children": [{
12+
"name": "main.c",
13+
"type": "c"
14+
}, {
15+
"name": "main.js",
16+
"type": "javascript",
17+
}, {
18+
"name": "main.html",
19+
"type": "html",
20+
}]
21+
}, {
22+
"name": "build.ts",
23+
"type": "typescript",
24+
}, {
25+
"name": "README.md",
26+
"type": "markdown",
27+
}],
28+
"openedFiles": [
29+
["README.md"]
30+
]
31+
}
32+
},
33+
{
234
"name": "C Hello World",
335
"description": `# Hello World in C
436
Creates a C project that prints "Hello World" using a minimal POSIX API.
@@ -22,21 +54,9 @@ Creates a C project that prints "Hello World" using a minimal POSIX API.
2254
}, {
2355
"name": "build.ts",
2456
"type": "typescript",
25-
"data": `gulp.task("build", async () => {
26-
const data = await Service.compileFile(project.getFile("src/main.c"), "c", "wasm", "-g -O3");
27-
const outWasm = project.newFile("out/main.wasm", "wasm");
28-
outWasm.setData(data);
29-
const result = await Service.disassembleWasm(data);
30-
outWasm.buffer.setValue(result);
31-
});
32-
33-
gulp.task("default", ["build"], async () => {});`
3457
}, {
3558
"name": "README.md",
3659
"type": "markdown",
37-
"data": `# Hello World in C
38-
A C project that prints "Hello World" using a minimal POSIX API.
39-
`
4060
}],
4161
"openedFiles": [
4262
["README.md"]

tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
},
1212
"include": [
1313
"./src/**/*"
14+
],
15+
"exclude": [
16+
"./templates/**/*"
1417
]
1518
}

0 commit comments

Comments
 (0)