|
67 | 67 |
|
68 | 68 | install_header |
69 | 69 |
|
| 70 | +ensure_webinteractive_cpp() { |
| 71 | + local dest="$ROOT_DIR/Lib/WebInteractive.cpp" |
| 72 | + if [[ -f "$dest" ]]; then |
| 73 | + return |
| 74 | + fi |
| 75 | + cat >"$dest" <<'EOF' |
| 76 | +#include "Lib/WebInteractive.hpp" |
| 77 | +
|
| 78 | +#ifdef __EMSCRIPTEN__ |
| 79 | +#include <emscripten.h> |
| 80 | +
|
| 81 | +extern "C" { |
| 82 | +EM_ASYNC_JS(char*, vampire_async_readline, (const char* prompt), { |
| 83 | + if (typeof Module.vampireReadline !== 'function') { return 0; } |
| 84 | + const text = prompt ? UTF8ToString(prompt) : ""; |
| 85 | + const response = await Module.vampireReadline(text); |
| 86 | + if (response === undefined || response === null) { return 0; } |
| 87 | + const len = lengthBytesUTF8(response) + 1; |
| 88 | + const buf = _malloc(len); |
| 89 | + stringToUTF8(response, buf, len); |
| 90 | + return buf; |
| 91 | +}); |
| 92 | +} |
| 93 | +#endif |
| 94 | +EOF |
| 95 | + echo "Ensured source: ${dest#$ROOT_DIR/}" |
| 96 | +} |
| 97 | + |
| 98 | +ensure_webinteractive_cpp |
| 99 | + |
70 | 100 | run_patch "Add WebInteractive.cpp implementation" '*** Add File: Lib/WebInteractive.cpp |
71 | 101 | #include "Lib/WebInteractive.hpp" |
72 | 102 |
|
|
192 | 222 | run_patch "List WebInteractive.cpp in sources" '--- a/cmake/sources.cmake |
193 | 223 | +++ b/cmake/sources.cmake |
194 | 224 | @@ |
195 | | - Lib/System.cpp |
196 | | - Lib/System.hpp |
197 | | - Lib/Timer.cpp |
198 | | - Lib/Timer.hpp |
| 225 | + Lib/System.cpp |
| 226 | + Lib/System.hpp |
| 227 | + Lib/Timer.cpp |
| 228 | + Lib/Timer.hpp |
199 | 229 | + Lib/WebInteractive.cpp |
200 | | - Lib/TriangularArray.hpp |
201 | | - Lib/TypeList.hpp |
202 | | - Lib/Vector.hpp |
203 | | - Lib/VirtualIterator.hpp |
| 230 | + Lib/TriangularArray.hpp |
| 231 | + Lib/TypeList.hpp |
| 232 | + Lib/Vector.hpp |
| 233 | + Lib/VirtualIterator.hpp |
204 | 234 | ' |
205 | 235 |
|
| 236 | +# Fallback: ensure WebInteractive.cpp is in sources.cmake |
| 237 | +SRC_PATH="$ROOT_DIR/cmake/sources.cmake" |
| 238 | +if [[ -f "$SRC_PATH" ]]; then |
| 239 | + if ! grep -q "Lib/WebInteractive.cpp" "$SRC_PATH"; then |
| 240 | + SRC_PATH="$SRC_PATH" python - <<'PY' |
| 241 | +from pathlib import Path |
| 242 | +import os |
| 243 | +
|
| 244 | +path = Path(os.environ["SRC_PATH"]) |
| 245 | +text = path.read_text() |
| 246 | +needle = "Lib/Timer.hpp\n" |
| 247 | +insert = "Lib/Timer.hpp\n Lib/WebInteractive.cpp\n" |
| 248 | +if needle in text: |
| 249 | + text = text.replace(needle, insert, 1) |
| 250 | + path.write_text(text) |
| 251 | + print("Applied: List WebInteractive.cpp in sources (fallback)") |
| 252 | +PY |
| 253 | + fi |
| 254 | +fi |
| 255 | + |
206 | 256 | echo "Interactive patch completed." |
0 commit comments