Source

chart / chart1 / chart1.ml

Full commit
open Js

module OnLoad = struct
  (*
    <script type="text/javascript">
      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);
    </script>
  *)

  (* Direct unsafe eval. Just works fine. *)
  (*
  let _ = 
    Unsafe.eval_string "google.setOnLoadCallback(drawChart);"
  *)

  (* Unsafe meth_call *)
  (*
  let _ = 
    let drawChart = Unsafe.variable "drawChart" in
    Unsafe.meth_call google "setOnLoadCallback" [| drawChart |]
  *)

end

(* google object *)
class type google = object
  method setOnLoadCallback : 'a -> unit meth
end
let google : google t = Unsafe.variable "google"

(* method call with variable *)
(*
let _ = 
  let drawChart = Unsafe.variable "drawChart" in
  (* ## method must always fully applied with explicit parens!!! *)
  (* WRONG: gObj##setOnLoadCallback drawChart *)
  google##setOnLoadCallback(drawChart) 
*)

(* ML function as argument *)
let _ = 
  let drawChart = Unsafe.variable "drawChart" in
  let callDrawChart () = Unsafe.fun_call drawChart [||] in
  google##setOnLoadCallback(callDrawChart)