Commits

camlspotter  committed 9edcf03 Merge

merge

  • Participants
  • Parent commits ba1400c, 94c21ee

Comments (0)

Files changed (5)

 open Js
 
-type int_t = int
-type float_t = float
+type int_t = int t
+type float_t = float t
 type string_t = js_string t
 type 'a array_t = 'a js_array t
 
 
 let any (a : 'a t) : any t = Obj.magic a
 
-let alert s = ignore (Unsafe.fun_call (Unsafe.variable "alert") [| Unsafe.inject (Js.string s) |])
+external int : int -> int t = "%identity"
 
+let alert s = ignore (Js.Unsafe.fun_call (Js.Unsafe.variable "alert") [| Js.Unsafe.inject (Js.string s) |])
+
 
 (** Some shorter names of JS objects *)
 
-type int_t = int
-type float_t = float
+type int_t = int t
+type float_t = float t
 type string_t = js_string t
 type 'a array_t = 'a js_array t
 
 
 val any : 'a t -> any t
 
+external int : int -> int t = "%identity"
+
 val alert : string -> unit
   (** JS alert function *)

File lib/xUnsafe.ml

 let literal = Js.Unsafe.variable (* Actually this does not work, if I put the definition here. *)
 
-(* Strange workaround... *)    
-let literal s = Js.Unsafe.eval_string (Printf.sprintf "function literal() { return %s; } literal();" s)
-
+(* A workaround... *)    
+let literal s = Js.Unsafe.eval_string (Printf.sprintf "( %s )" s)

File test/OMakefile

 OCAMLCFLAGS += -I ../lib
 OCAMLOPTFLAGS += -I ../lib
 
+# Enforce ../lib/xJs.cmo exists before compilation
+.SCANNER: scan-ocaml-%: ../lib/xJs.cmo
+%.cmx %.cmo %.cmi %.cma %.cmxa %.annot %.spot %.spit : ../lib/xJs.cmo
+
 FILES[] =
     ../lib/xJs
     chart

File test/chart.ml

 open Js
 open XJs
-(* open Std *)
+open Std
 open Google
 open Lwt
 
   ignore begin
     Data.get "data.txt" >>= fun rows ->
     data##addRows(Js.array (Array.of_list (List.map (fun (x,y) -> 
-      Js.array [| Obj.magic x; Obj.magic y; |]) rows)));
+      Js.array [| int x; int y; |]) rows)));
     return ()
   end
 
     let rec iter = function
       | [] -> return ()
       | (x,y)::xys ->
-          data##addRows(Js.array [| Js.array [| Obj.magic x; Obj.magic y; |] |]);
+          data##addRows(Js.array [| Js.array [| int x; int y; |] |]);
           Lwt_js.sleep 0.2 >>= fun () ->
           iter xys (* It seems not to be executed.... Hmmm *)
     in