Source

opycaml / js_of_ocaml / opy_of_ocaml.ml

open Opycaml.OOApi
open OPy

module Js : sig
  type 'a t
  type 'a gen_prop
  type 'a readonly_prop = < get : 'a> gen_prop
  type 'a meth
  val dict : #o_Dict -> 'a t
  module Unsafe : sig
    val get : 'a t -> string -> 'b
    val meth_call : 'a t -> string -> #o_Object array -> 'b
    val inject : #o_Object -> o_Object
  end
end = struct
  type 'a t = o_Dict
  type 'a gen_prop
  let dict = Obj.magic
  module Unsafe = struct
    let get (o : 'a t) name = Obj.magic (o#getItemString name)
    let meth_call (o : o_Dict) name args = 
      Obj.magic (Object.callObject (Callable.coerce (o#getItemString name)) (Array.to_list args ))
    let inject = Obj.magic
  end

  type 'a readonly_prop = < get : 'a> gen_prop
  type 'a meth
end

let import_module name = Js.dict (Import.importModule name)#getDict