1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
<!-- Title = calling Eiffel from -->
<CENTER><P><IMG SRC="worker.gif" ALT="[Line]"><br>
<b>This page is not finished yet</b></P></center>
<TABLE BORDER=0 CELLSPACING=5 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#3366FF" NOSAVE >
<TR NOSAVE>
<TD NOSAVE>
<CENTER><FONT COLOR="#FFFFFF" SIZE=+3><B>Cecil</B></FONT></CENTER>
</TD>
</TR>
</TABLE>
<BR><BR><BR>
<P>
Here is the information you need if you want to call some Eiffel
features from C code. To call C functions/macros from Eiffel see
the documentation about <A HREF="external.html">externals</A>
(<code>man/external</code> in the distribution).
</P>
<P>
In order to call some Eiffel feature from C, you must use the
<TT>-cecil <cecil_file></TT> option with command <TT>compile</TT>
or <TT>compile_to_c</TT>.
The <TT><cecil_file></TT> allows you to give the list of features
you want to call from C. The corresponding stub routines will be
automatically generated by SmartEiffel.
<BR>
When the <TT>-cecil</TT> option is used, command <TT>compile_to_c</TT>
also produces an additional C heading file which includes the needed
C prototypes.
</P>
<P>
Your <TT><cecil_file></TT> must contain at least two lines.
The first line is the
name of the C heading file to produce (it may be useful if you need
to create a C library). Other lines have the following structure:
</P>
<TABLE ALIGN=center BORDER=0 CELLSPACING=2 CELLPADDING=2 COLS=3>
<TR> <TD><c_name></TD> <TD><live_eiffel_type></TD>
<TD><feature_name></TD> </TR>
</TABLE>
<P>
The <TT><c_name></TT> is the name of the C function defined by
<TT>compile_to_c</TT> to wrap the Eiffel call.
The couple <TT><live_eiffel_type> <feature_name> </TT>
gives the complete name of the Eiffel feature to call. For example:
</P>
<TABLE ALIGN=center BORDER=0 CELLSPACING=2 CELLPADDING=2 COLS=3>
<TR> <TD>IsEiffelStringEmpty</TD> <TD>STRING</TD> <TD>empty</TD> </TR>
<TR> <TD>STRINGitem</TD> <TD>STRING</TD> <TD>item</TD> </TR>
<TR> <TD>strgrtr</TD> <TD>STRING</TD> <TD>infix ">"</TD> </TR>
<TR> <TD>array_of_int_count</TD> <TD>ARRAY[INTEGER]</TD> <TD>count</TR>
<TR> <TD>X_f</TD> <TD>X</TD> <TD>f</TR>
</TABLE>
<P>
Keep in mind that the <TT><live_eiffel_type></TT> must be
really <I>live</I>:
if <TT><live_eiffel_type></TT> is <TT>ARRAY[INTEGER]</TT> for example,
your Eiffel program is supposed to create at least one <TT>ARRAY[INTEGER]</TT>.
</P>
<P>
The name of the feature to call, <TT><feature_name></TT> may even be
an infix or a prefix feature name. The syntax is the same as the one used in
Eiffel source.
</P>
<P>
Since attributes are features, if is of course possible to access them
with this mechanism.
</P>
<P>
A call to <TT>X_f</TT> in the C code is equivalent to a call to <TT>x.f</TT>
in Eiffel, with <TT>x</TT> of type <TT>X</TT> <I>or any descendant of
<TT>X</TT></I>.
Indeed, <TT>X_f</TT> takes care of late binding. This means that
<TT>X_f</TT> can be called on any (Current) argument of type <TT>X</TT>
or heir of <TT>X</TT>.
</P>
<P>
As <TT><cecil_file></TT> is parsed by the SmartEiffel parser, it
may contain Eiffel comments.
</P>
<P>
Here is one example of a Cecil file (others can be found in directories
<TT>SmartEiffel/tutorial/cecil/example*</TT>):
</P>
<PRE>
-- The name of the include C file :
eiffel.h
-- The features you want to call from C :
array_of_animal_item ARRAY[ANIMAL] item
array_of_animal_lower ARRAY[ANIMAL] lower
array_of_animal_upper ARRAY[ANIMAL] upper
cry ANIMAL cry
string_to_external STRING to_external
</PRE>
People who tinker with the C code generated by SmartEiffel, not limiting
themselves to the Cecil and/or external interfaces, should also read
<A HREF="c_code.html">this page about the C code generated by SmartEiffel</A>.
Otherwise they might get into trouble.
<CENTER><P><IMG SRC="se-line.gif" ALT="[Line]" HEIGHT=16 WIDTH=550>
<BR>
<I><FONT SIZE=-1>Copyright © Dominique COLNET and Suzanne COLLIN -
<A HREF="mailto:SmartEiffel@loria.fr"><SmartEiffel@loria.fr></A> <BR>
<!-- hhmts start -->
Last modified: Tue Feb 11 12:10:59 CET 2003
<!-- hhmts end -->
<BR>
</FONT></I><BR></P></CENTER>
|