/*
    Marco's Chess: WebAssembly build of Sjeng, page <-> engine input.
    Copyright (C) 2026 Marco Seman. Licensed GPL-3.0-or-later; see ../../LICENSE.

    Sjeng waits for each command with rinput(). In the browser there is no
    stdin, so rinput() calls this function, which suspends the engine (Asyncify)
    until the page sends the next line through Module.nextLine().
*/
#include <emscripten.h>

EM_ASYNC_JS(int, sjeng_wasm_next_line, (char *buf, int size), {
  const line = await Module.nextLine();
  stringToUTF8(line, buf, size);
  return lengthBytesUTF8(line);
});
