Version française
Home     About     Download     Resources     Contact us    
Browse thread
scripting the toplevel
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus E.L. <ls-ocaml-developer-2006@m...>
Subject: Re: [Caml-list] scripting the toplevel


I picked the following trick from Gerd Stolpmann's findlib;

   exception Toplevel_error of string;;

   let toplevel_exec s =
     let l = Lexing.from_string s in
     let ph = !Toploop.parse_toplevel_phrase l in
     let fmt = Format.make_formatter (fun _ _ _ -> ()) (fun _ -> ()) in
       if not (Toploop.execute_phrase false fmt ph)
       then raise (Toplevel_error s)
   ;;


You can now do

   toplevel_exec "#load " ^ (String.escaped user_module) ^ ";;"

Regards -- Markus