From: Guillaume Y. <gui...@ci...> - 2009-07-04 14:19:19
|
Hello. Still trying to build up my OCaml module. I'd like to ask for some explanations on how to write functionWrappers that takes typemaps into account. functionWrapper code can be found below. I written the code trying to grap here and there what might be useful, but the end of this code is still something that confuses me. The thing that confuses me most is how to get typemaps to generate some appropriate code in these wrapper objecs. Help, guidance and documentation would be appreciated. Guillaume Yziquel. > int OCAML::functionWrapper (Node * n) { > // Swig 1.3 Documentation: 35.10.6 Module I/O and wrapper skeleton > > // Get some useful attributes of this function > String * name = Getattr(n, "sym:name" ); > String * type = Getattr(n, "type" ); > ParmList * parms = Getattr(n, "parms" ); > // Conversion of parms to a the string parmstr > String * parmstr = ParmList_str_defaultargs(parms); > String * func = SwigType_str(type, NewStringf("%s(%s)", name, parmstr)); > String * action = Getattr(n, "wrap:action"); > > // Declaration of the wrapper. > Wrapper * f = NewWrapper(); > > // Construction of the wrapper name. > String * wrapper_name = Swig_name_wrapper(name); > // Checking that the wrapper name doesn't conflict with another symbol. > if (!addSymbol(name, n)) { > DelWrapper(f); > return SWIG_ERROR; > } > // Registering the wrapper name. > Setattr(n, "wrap:name", wrapper_name); > > if (classmode && in_constructor) { > Printf(f_mlcdecl, "external %s : Obj.t -> Obj.t = \"%s\"\n", wrapper_name, wrapper_name); > Printf(f_mlbody, "val underlying_cpp_object = %s constructing_argument\n", wrapper_name); > } else if (classmode) { > Printf(f_mlcdecl, "external %s : Obj.t * Obj.t -> Obj.t = \"%s\"\n", wrapper_name, wrapper_name); > Printf(f_mlbody, "method %s x = %s (underlying_cpp_object, x)\n", name, wrapper_name); > } > > // Documentation on wrapper objects can be found in > // /usr/share/doc/swig-doc/Devel/wrapobj.html > Printv(f->def, "CAML_VALUE ", wrapper_name, " (", NIL); > Printv(f->def, "CAML_VALUE args", NIL); > Printv(f->def, ") {\n", NIL); > Wrapper_add_local(f, "args", "CAMLparam1(args)"); > Wrapper_add_local(f, "ret" , "SWIG_CAMLlocal2(swig_result, rv)"); > Wrapper_add_local(f, "_v" , "int _v = 0"); > type = SwigType_typedef_qualified(type); > emit_parameter_variables(parms, f); > emit_attach_parmmaps(parms, f); > Setattr(n, "wrap:parms", parms); > int numargs = emit_num_arguments(parms); > int numreq = emit_num_required(parms); > Printf(f->code, "swig_result = Val_unit;\n"); > Printf(f->code, "}\n"); > Wrapper_print(f, f_wrappers); > > return SWIG_OK; > } |