Skip to content
Snippets Groups Projects
Commit f55587a3 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[server] added Jfile converters

parent 993f9409
No related branches found
No related tags found
No related merge requests found
...@@ -210,6 +210,14 @@ struct ...@@ -210,6 +210,14 @@ struct
let to_json s = `String s let to_json s = `String s
end end
module Jfile : S with type t = Filepath.Normalized.t =
struct
type t = Filepath.Normalized.t
let jtype = Jstring
let of_json js = Ju.to_string js |> Filepath.Normalized.of_string
let to_json (file:t) = `String (file :> string)
end
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
(* --- Text Datatypes --- *) (* --- Text Datatypes --- *)
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
......
...@@ -81,6 +81,7 @@ module Jint : S with type t = int ...@@ -81,6 +81,7 @@ module Jint : S with type t = int
module Jfloat : S with type t = float module Jfloat : S with type t = float
module Jstring : S with type t = string module Jstring : S with type t = string
module Jalpha : S with type t = string module Jalpha : S with type t = string
module Jfile : S with type t = Filepath.Normalized.t
(** Rich text encoding, see [Jbuffer]. *) (** Rich text encoding, see [Jbuffer]. *)
module Jtext : S with type t = json module Jtext : S with type t = json
......
...@@ -65,20 +65,20 @@ let () = ...@@ -65,20 +65,20 @@ let () =
let () = let () =
Request.register ~package ~kind:`SET ~name:"load" Request.register ~package ~kind:`SET ~name:"load"
~descr:(Md.plain "Load a save file. Returns an error, if not successfull.") ~descr:(Md.plain "Load a save file. Returns an error, if not successfull.")
~input:(module Jstring) ~input:(module Jfile)
~output:(module Joption(Jstring)) ~output:(module Joption(Jstring))
(fun file -> (fun file ->
try Project.load_all (Filepath.Normalized.of_string file); None try Project.load_all file; None
with Project.IOError err -> Some err) with Project.IOError err -> Some err)
let () = let () =
Request.register ~package ~kind:`SET ~name:"save" Request.register ~package ~kind:`SET ~name:"save"
~descr:(Md.plain "Save the current session. Returns an error, if not successfull.") ~descr:(Md.plain "Save the current session. Returns an error, if not successfull.")
~input:(module Jstring) ~input:(module Jfile)
~output:(module Joption(Jstring)) ~output:(module Joption(Jstring))
(fun file -> (fun file ->
try Project.save_all (Filepath.Normalized.of_string file); None try Project.save_all file; None
with Project.IOError err -> Some err) with Project.IOError err -> Some err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment