Working example. See Examples/ocaml/shapes.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4489 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Art Yerkes 2003-03-10 04:14:04 +00:00
commit de9c786cad
7 changed files with 99 additions and 32 deletions

View file

@ -91,10 +91,12 @@ public:
/* wrap a ocaml object, optionally taking ownership */
__DIRECTOR__(value self, int disown): _self(self), _disown(disown) {
register_global_root(&_self);
}
/* discard our reference at destruction */
virtual ~__DIRECTOR__() {
remove_global_root(&_self);
__disown();
// Disown is safe here because we're just divorcing a reference that
// points to us.
@ -102,7 +104,7 @@ public:
/* return a pointer to the wrapped ocaml object */
value __get_self() const {
return _self;
return callback(*caml_named_value("caml_director_get_self"),_self);
}
/* get the _up flag to determine if the method call should be routed
@ -188,7 +190,7 @@ let new_derived_object cfun x_class args =
let obj =
cfun (match args with
C_list argl ->
(C_list ((C_obj new_class) :: argl))
(C_list ((C_director_core (C_obj new_class,ob_ref)) :: argl))
| a -> (C_list [ C_director_core
(C_obj new_class,ob_ref) ; a ])) in
ob_ref := Some obj ;

View file

@ -94,7 +94,8 @@ let disown_object obj =
let _ = Callback.register "caml_obj_disown" disown_object
let director_get_self obj =
match obj with
C_director_core (self,r) -> self
C_obj o -> obj
| C_director_core (self,r) -> self
| _ -> raise (Failure "Not a director core object")
let _ = Callback.register "caml_director_get_self" director_get_self

View file

@ -29,3 +29,4 @@
%include "typemaps.i"
%include "typecheck.i"
%include "exception.i"
%include "director.swg"

View file

@ -190,9 +190,15 @@
temp = ($*1_ltype) MZ_TO_C($input);
$1 = &temp;
}
%typemap(outv) C_NAME {
$1 = MZ_TO_C($input);
}
%typemap(argout) C_NAME & {
swig_result = caml_list_append(swig_result,C_TO_MZ((long)*$1));
}
%typemap(inv) C_NAME {
args = caml_list_append(args,C_TO_MZ($1_name));
}
%enddef
SIMPLE_MAP(bool, caml_val_bool, caml_long_val);