C <-> Erlang with IC
Dan Gudmundsson
dgud@REDACTED
Fri Aug 20 15:49:42 CEST 1999
Something like this should be doable I guess.
Define in IDL:
#include <erlang.idl>
module dynamic
{
interface dyn_erl
{
Status erlApply(in string module,
in string function,
in erlang::term listOfArgs,
in out erlang::term res);
}
}
And in the erlang callback module:
erl_apply(State, Mod, Fun, Args) ->
case catch apply(list_to_atom(Mod),
list_to_atom(Fun), Args) of
{'EXIT', R} ->
{reply, {error, []}, State}};
Result ->
{reply, {ok, Result}, State}}
end.
In 'C' the call would look something like
ETERM * result, empty;
empty = erl_mk_empty_list();
status = dynamic_erlApply(NULL, "erlang", "date", empty, &result, env);
See the erl_interface doc about handling erlang data types in C.
/Dan
Mark NG writes:
> On Fri, Aug 20, 1999 at 12:12:29AM +1000, Torbjorn Tornkvist wrote:
> >
> > Sorry, I know I shouldn't promote IG (since it is obsolete) but
>
> I have played with it a bit, and like it more than IC for some
> tasks. :)
>
>
> > I can't help myself. Actually I would also be interested in how
> > you would do it with IC. Anyway, here is how you do it with IG:
> >
>
> <example snipped>
>
> Thanks for the example, but I am really after is something like
> where I can pass a lambda to a C function and get that C function
> to invoke this piece of Erlang code.
>
> The IC manual has examples on how to call "static" Erlang functions
> from C, but not dynamic ones.
>
>
> mark
>
--
Dan Gudmundsson Project: Mnesia, Erlang/OTP
Ericsson Utvecklings AB Phone: +46 8 727 5762
UAB/F/P Mobile: +46 70 519 9469
S-125 25 Stockholm Visit addr: Armborstv 1
More information about the erlang-questions
mailing list