Source

opycaml / js_of_ocaml2 / testoox.ml

Full commit
open Opycaml.OOApi
open Opy_of_ocaml

class type module_string = object
  method lowercase : o_String readonly_prop
  method capitalize : #o_String -> o_String meth
end

(* Somehow the following object must be created from the above *) 
let module_string_wrap = object
  method lowercase = OPy.String.coerce
  method capitalize = OPy.String.coerce
end

let _ =
  let module_string : module_string t * _ = import_module "string", module_string_wrap in
  (* from string import * *)
  let lowercase =
    let ((module_string_1 : (< .. > as 'x1) Js.t), wrapper) = module_string in
    let _ (arg1 : 'x1) =
      (arg1#lowercase : < get : 'x2; .. > Js.gen_prop)
    in 
    (* (Js.Unsafe.get module_string_1 "lowercase" : 'x2)  *)
    wrapper#lowercase
    ((Obj.magic module_string_1 : o_Dict)#getItemString "lowercase")
  in

  let res =
    let (module_string_2 : (< .. > as 'x3) Js.t), wrapper = module_string in
    let _ (arg2 : 'x3) =
      (arg2#capitalize : 'x4 -> 'x5 Js.meth)
    in
    wrapper#capitalize
      (Js.Unsafe.meth_call module_string_2 "capitalize" [| Js.Unsafe.inject ((Obj.magic lowercase) : 'x4) |] : 'x5)
  in prerr_endline res#asString