1. camlspotter
  2. opycaml

Commits

camlspotter  committed 4748c12 Merge

merge

  • Participants
  • Parent commits 23d8cb1, f8b1b47
  • Branches default

Comments (0)

Files changed (4)

File api.ml

View file
         **)
 
       external unsafe_embed : 'a -> _CObject t = "opycaml_embed_ocaml_value"
-	(** embed any OCaml value into Python's CObject. Unsafe. *)
+	(** Unsafe: embed any OCaml value into Python's CObject. *)
 
       external embed_closure : ([> _Tuple] t -> _Object t) -> _Closure t = "opycaml_create_closure_wrap"
+	(** Embed an OCaml function of type [[> _Tuple] t -> _Object t] to a Python object *)
     end = struct
   
       external none : unit -> _None t = "opycaml_none"
 	(** Object method call *)
       val obj : [> _Object ] t -> _Object t
 	(** Forget the type of the object *)
+      val repr_string : [> _Object ] t -> string
+      (** obtain OCaml string of repr *)
+      val str_string : [> _Object ] t -> string
+	(** obtain OCaml string of str *)
     end = struct
       let call callable ?kwd list =
 	_internal_call callable (Tuple.from_list list) kwd
 	| list -> _internal_callObject callable (Some (Tuple.from_list list))
 
       let obj t : _Object t = unsafe_coerce t
+
+      let repr_string t = String.asString (repr t)
+      let str_string t = String.asString (str t)
     end
 
     include X

File api_ml.c

View file
 
 void opycaml_decref(value obj){
     PyObject *o = PyObject_val(obj);
-    PyObject *p = PyCFunction_GetSelf(o);
+//    PyObject *p = PyCFunction_GetSelf(o);
 //    if( PyCFunction_Check(o) ){ 
 //        fprintf(stderr, "PYCFunction DECR! %d(%d) =>\n", 
 //                o->ob_refcnt,

File test.ml

View file
     let py_ocaml_1 = Base.unsafe_embed 1 in
     Base.debug "py_ocaml_1" py_ocaml_1;
 
-    prerr_endline "*** OCaml closure wrapping";
+    prerr_endline "*** inserting a closure into module opycaml";
     let f (args : _Tuple t) : _Object t =
-      Format.eprintf "#Args!!@.";
+      let i = ref 0 in
+      List.iter (fun t -> 
+	Format.eprintf "Arg %d : %s@." !i (Object.repr_string t);
+	incr i;
+      ) (Tuple.to_list args);
       Object.obj (Base.none ())
     in
     
-    let fo = Base.embed_closure f in
-    Base.debug "fo" fo;
-
-    prerr_endline "*** inserting a closure into module opycaml";
     let m = Import.importModule "opycaml" in
-    Module.setItemString m "f" fo;
+    Module.setClosureString m "f" f;
     prerr_endline "* check / import opycaml / opycaml.__dict__ / opycaml.f(1)";
 
     prerr_endline "*** Entering the toploop";

File tests/OMakefile

View file
 OCAML_LIBS = ../opycaml
 OCAMLFLAGS += -I ..
 
+%.cmx: ../opycaml.cmxa
+%.cmo: ../opycaml.cma
+
 .DEFAULT: $(OCamlProgram from_string_iteration, from_string_iteration)
 .DEFAULT: $(OCamlProgram set_closure_string, set_closure_string)