1

I have a function that uses a mutable variable that takes strings and returns strings. (its a read eval print loop interpreter)

I tried exporting it as such:

let () =
  Js.export_all
  (object%js
    method js_run_repl = Js.wrap_callback js_run_repl
  end)

Heres a snippet of the function im exporting

let js_run_repl str =
  match String.(compare str "quit") with
  | 0 -> "bye"
  | _ -> ...

regardless of my input it always returns bye, calling the function directly in ocaml produced the expected behaviour. Heres the output from node:

> var mod = require('./main.bc');
undefined
> mod.js_run("constant P : Prop");
MlBytes { t: 0, c: 'bye', l: 3 }
> 

Its also peculiar why the function is called js_run instead of js_run_repl. the latter is undefined according to node.

1 Answer 1

1
let () =
  Js.export_all
  (object%js
    method js_run_repl str = 
      str
      |> Js.to_string
      |> js_run_repl
      |> Js.string
  end)

I had to convert the strings explicitly to ocaml strings and back to js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.