caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] [C] call Caml method
@ 2011-10-15  9:30 Kakadu
  2011-10-15  9:44 ` Jérémie Dimino
  0 siblings, 1 reply; 3+ messages in thread
From: Kakadu @ 2011-10-15  9:30 UTC (permalink / raw)
  To: Caml List

[-- Attachment #1: Type: text/plain, Size: 874 bytes --]

Hi!

I've found in OCaml manual how to call object's method without arguments.
But I have no idea how to call method with some arguments.
For example I have this OCaml code:

external call_meth: < .. > -> unit = "call_a_meth"

class a = object
  method foo x = print_endline x
end;;

and C code:

CAMLprim
value call_a_meth(value obj) {
  CAMLparam1(obj);
  CAMLlocal3(meth, meth2, arg1);
  meth = caml_get_public_method(obj, caml_hash_variant("foo") ) ;
  if (meth == 0)
       printf ("Fuck\n");
  arg1 = Val_int(1);
//  caml_callback2(meth, obj, arg1); // segfault in this line
  meth2 = caml_callback(meth, obj);  // no crash, but method's body is not
being executed
  caml_callback(meth2, arg1);        // segfault.
  CAMLreturn(Val_unit);
}

I've tested three variants of calling above, But I still can't call a method
with parameters. Any ideas?

Best wishes,
Kakadu

[-- Attachment #2: Type: text/html, Size: 2813 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] [C] call Caml method
  2011-10-15  9:30 [Caml-list] [C] call Caml method Kakadu
@ 2011-10-15  9:44 ` Jérémie Dimino
  2011-10-15 11:22   ` Kakadu
  0 siblings, 1 reply; 3+ messages in thread
From: Jérémie Dimino @ 2011-10-15  9:44 UTC (permalink / raw)
  To: Kakadu; +Cc: Caml List

Hi,

Le samedi 15 octobre 2011 à 13:30 +0400, Kakadu a écrit : 
>   arg1 = Val_int(1);
> //  caml_callback2(meth, obj, arg1); // segfault in this line

In your example arg1 should be a string, here it is an int. And the
commented line is the right way to call the method.

Cheers,

-- 
Jérémie




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] [C] call Caml method
  2011-10-15  9:44 ` Jérémie Dimino
@ 2011-10-15 11:22   ` Kakadu
  0 siblings, 0 replies; 3+ messages in thread
From: Kakadu @ 2011-10-15 11:22 UTC (permalink / raw)
  To: Jérémie Dimino; +Cc: Caml List

[-- Attachment #1: Type: text/plain, Size: 494 bytes --]

O_O
I want to install OCaml type-checker into my mind!

Thanks, Jérémie!

On Sat, Oct 15, 2011 at 1:44 PM, Jérémie Dimino <jeremie@dimino.org> wrote:

> Hi,
>
> Le samedi 15 octobre 2011 à 13:30 +0400, Kakadu a écrit :
> >   arg1 = Val_int(1);
> > //  caml_callback2(meth, obj, arg1); // segfault in this line
>
> In your example arg1 should be a string, here it is an int. And the
> commented line is the right way to call the method.
>
> Cheers,
>
> --
> Jérémie
>
>
>

[-- Attachment #2: Type: text/html, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-10-15 11:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-15  9:30 [Caml-list] [C] call Caml method Kakadu
2011-10-15  9:44 ` Jérémie Dimino
2011-10-15 11:22   ` Kakadu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).