Repository navigation
Expand file tree
/
Copy pathLifeEmbedded.cpp
More file actions
42 lines (39 loc) · 1.59 KB
/
Copy pathLifeEmbedded.cpp
File metadata and controls
42 lines (39 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SPDX-License-Identifier: Apache-2.0 OR CECILL-B
// Author: Ambroise Leclerc
// Created: 2026-10-20
//
// WebFront — examples
// Role: Embedded stage of the Game of Life walkthrough: the compiled UI served from the embedded provider.
// Thread: ui-loop | Alloc: unrestricted
// LLM: final stage of the README walkthrough; the provider is generated by wf embed
#include <webfront/WebFront.hpp>
#include WEBFRONT_LIFE_ASSETS_HEADER
#include "../PortOption.hpp"
#include "Life.hpp"
#include "LifeFrontend.hpp"
#include <iostream>
#include <string_view>
int main(int argc, char** argv) {
// The check of an installed copy (docs/DISTRIBUTION.md): the embedded interface is there, without a window or a server.
if (argc == 2 && std::string_view{argv[1]} == "--check") {
for (const auto* asset : {"index.html", "app.js", "app.css"})
if (!webfront::fs::LifeUI::open(asset)) {
std::cerr << "The embedded interface lacks " << asset << '\n';
return 1;
}
std::cout << "WebFront Life " << webfront::version << ": embedded interface present\n";
return 0;
}
if (!webfront::demo::applyPortOption(argc, argv) || argc != 1) {
std::cerr << "Usage: WebFrontLifeEmbedded [--port <n>] (WEBFRONT_PORT=0 asks for a free port) | --check\n";
return 2;
}
try {
webfront::demo::LifeAppWithAssets<webfront::fs::LifeUI> app;
app.cppFunction("life.step", &webfront::demo::nextLife);
app.show();
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}