Dear Jon,
interacting between Lisp and javascript in a browser can be done by
directly calling functions from ECL's C interface from javascript or
vice-versa using the available methods to call javascript from C and
ECL's C foreign function interface. A description for how to call C from
javascript and vice-versa can be found at
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html
Another thing to keep in mind is the asynchronous nature of javascript
running in a browser which does not integrate easily with the
synchronous IO interface of Common Lisp. If you want to keep the Lisp
runtime running in the background, waiting for input to arrive, there
are two options: either compile with LDFLAGS="-sASYNCIFY"
(https://emscripten.org/docs/porting/asyncify.html) or run ECL in a
separate thread (by means of a WebWorker) while communicating with the
UI thread via Atomics.wait and SharedArrayBuffer's.
For an example of the latter option, you can look at the ECL repl
https://repl.chee.party/ that Daniel has linked to or also at
https://sourceforge.net/u/mgerbershagen/maxima/ci/emscripten-port/tree/
which contains a very rough early-stage port of the maxima computer
algebra system to a browser environment (in particular the wasm
subdirectory and the src/ecl-port.lisp file are relevant).
Best regards,
Marius Gerbershagen
Am 30.12.23 um 14:39 schrieb Jón Hallur Haraldsson:
Hi,
I've been toying around with the idea to run ecl in the browser since it
is now easy to build it using emscripten.
I have successfully interacted with the runtime using the extremely
awkward "window.prompt" native javascript pop up.
My experience in using ECL is in embedding it in C/C++
Has someone successfully used it to run in the browser without using the
"wasm-draw-to-canvas" and "windows.prompt" REPL
I'm assuming that this has nothing to do with ECL and is purely how
emscripten works.
Can I write a more embedded version which does not require me to
interact through the REPL in the browser.
If anyone has done any similar things I'd really like to hear about them.
Kindest regards.
Jon Hallur