Source

opycaml / xapi.ml

Full commit
(* Extended API which may be useful and should be integrated into Api *)

open Api

let (%) = Dict.getItemString
let (%!) x = Dict.getItemString (Dict.coerce x)

let (!:>) = Object.obj

let dict_of_alist kvs =
  let d = Dict.new_ () in
  List.iter (fun (k,v) -> Dict.setItem d k v) kvs;
  d
  
let dict_of_klist kvs =
  kvs |> List.map (fun (s,o) -> Py.String.fromString s, o) |> dict_of_alist

let call_obj o ?kwd xs = 
  let kwd = match kwd with
    | None -> None
    | Some xs -> Some (dict_of_klist xs)
  in
  Object.call (Callable.coerce o) ?kwd xs

let call_obj_ o ?kwd xs = call_obj o ?kwd xs  |> ignore

let import_module name = Module.getDict (Import.importModule name)