Quantcast
Channel: OCaml - Topics tagged dune
Viewing all articles
Browse latest Browse all 547

Replacing part of a running ocaml program using the Dynlink library

$
0
0

I am trying to replace (a small part) of my program while it is running using the Dynlink module. I have tried to replicate this example:
http://zderadicka.eu/plugins-in-ocaml-with-dynlink-library/

In my code, I have a plugface library, that is available to both main and the plugin. So I set the refs from the plugin, and can then read it using get_plugin () in my main exec.

let p = ref None
let get_plugin () : int Seq.t  =
  match !p with 
  | Some s -> s
  | None -> failwith "No plugin loaded"

plugin.ml

open Plugface
let () = 
  let _ = print_endline "version 3.21" in
  p := Some (Seq.cycle (List.to_seq [200]))

This works the first time like I would expect :slight_smile: .
However, when I edit my plugin.ml and then recompile it and try to load the “plugin.cmxs” for a second time in main.app. I don’t get an error, but also nothing really changes, it seems that it just running the old code again, instead of the new. Is this expected? Is it even possible what I try to do?

4 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 547

Trending Articles