Add Toploop.override_sys_argv
parent
b98461c3f3
commit
86daba0e90
|
@ -565,6 +565,13 @@ let loop ppf =
|
|||
|
||||
(* Execute a script. If [name] is "", read the script from stdin. *)
|
||||
|
||||
let override_sys_argv args =
|
||||
let len = Array.length args in
|
||||
if Array.length Sys.argv < len then invalid_arg "Toploop.override_sys_argv";
|
||||
Array.blit args 0 Sys.argv 0 len;
|
||||
Obj.truncate (Obj.repr Sys.argv) len;
|
||||
Arg.current := 0
|
||||
|
||||
let run_script ppf name args =
|
||||
let len = Array.length args in
|
||||
if Array.length Sys.argv < len then invalid_arg "Toploop.run_script";
|
||||
|
|
|
@ -120,3 +120,13 @@ val read_interactive_input : (string -> bytes -> int -> int * bool) ref
|
|||
(* Hooks for initialization *)
|
||||
|
||||
val toplevel_startup_hook : (unit -> unit) ref
|
||||
|
||||
(* Misc *)
|
||||
|
||||
val override_sys_argv : string array -> unit
|
||||
(* [override_sys_argv args] replaces the contents of [Sys.argv] by [args]
|
||||
and reset [Arg.current] to [0].
|
||||
|
||||
This is called by [run_script] so that [Sys.argv] represents
|
||||
"script.ml args..." instead of the full command line:
|
||||
"ocamlrun unix.cma ... script.ml args...". *)
|
||||
|
|
|
@ -539,12 +539,15 @@ let loop ppf =
|
|||
|
||||
(* Execute a script. If [name] is "", read the script from stdin. *)
|
||||
|
||||
let run_script ppf name args =
|
||||
let override_sys_argv args =
|
||||
let len = Array.length args in
|
||||
if Array.length Sys.argv < len then invalid_arg "Toploop.run_script";
|
||||
if Array.length Sys.argv < len then invalid_arg "Toploop.override_sys_argv";
|
||||
Array.blit args 0 Sys.argv 0 len;
|
||||
Obj.truncate (Obj.repr Sys.argv) len;
|
||||
Arg.current := 0;
|
||||
Arg.current := 0
|
||||
|
||||
let run_script ppf name args =
|
||||
override_sys_argv args;
|
||||
Compmisc.init_path ~dir:(Filename.dirname name) true;
|
||||
(* Note: would use [Filename.abspath] here, if we had it. *)
|
||||
begin
|
||||
|
|
|
@ -145,3 +145,13 @@ val toplevel_startup_hook : (unit -> unit) ref
|
|||
(* Used by Trace module *)
|
||||
|
||||
val may_trace : bool ref
|
||||
|
||||
(* Misc *)
|
||||
|
||||
val override_sys_argv : string array -> unit
|
||||
(* [override_sys_argv args] replaces the contents of [Sys.argv] by [args]
|
||||
and reset [Arg.current] to [0].
|
||||
|
||||
This is called by [run_script] so that [Sys.argv] represents
|
||||
"script.ml args..." instead of the full command line:
|
||||
"ocamlrun unix.cma ... script.ml args...". *)
|
||||
|
|
Loading…
Reference in New Issue