Skip to content

Commit f390931

Browse files
committed
latest. hopefully good and interactive?
1 parent 1c10ed5 commit f390931

1 file changed

Lines changed: 58 additions & 8 deletions

File tree

patchVampireInteractive.sh

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,36 @@ EOF
6767

6868
install_header
6969

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+
70100
run_patch "Add WebInteractive.cpp implementation" '*** Add File: Lib/WebInteractive.cpp
71101
#include "Lib/WebInteractive.hpp"
72102
@@ -192,15 +222,35 @@ fi
192222
run_patch "List WebInteractive.cpp in sources" '--- a/cmake/sources.cmake
193223
+++ b/cmake/sources.cmake
194224
@@
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
199229
+ 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
204234
'
205235

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+
206256
echo "Interactive patch completed."

0 commit comments

Comments
 (0)