aboutsummaryrefslogtreecommitdiffstats
path: root/system/doc/tutorial/ei.c
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2009-11-20 14:54:40 +0000
committerErlang/OTP <[email protected]>2009-11-20 14:54:40 +0000
commit84adefa331c4159d432d22840663c38f155cd4c1 (patch)
treebff9a9c66adda4df2106dfd0e5c053ab182a12bd /system/doc/tutorial/ei.c
downloadotp-84adefa331c4159d432d22840663c38f155cd4c1.tar.gz
otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.bz2
otp-84adefa331c4159d432d22840663c38f155cd4c1.zip
The R13B03 release.OTP_R13B03
Diffstat (limited to 'system/doc/tutorial/ei.c')
-rw-r--r--system/doc/tutorial/ei.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/system/doc/tutorial/ei.c b/system/doc/tutorial/ei.c
new file mode 100644
index 0000000000..b234a00768
--- /dev/null
+++ b/system/doc/tutorial/ei.c
@@ -0,0 +1,38 @@
+/* ei.c */
+
+#include "erl_interface.h"
+#include "ei.h"
+
+typedef unsigned char byte;
+
+int main() {
+ ETERM *tuplep, *intp;
+ ETERM *fnp, *argp;
+ int res;
+ byte buf[100];
+ long allocated, freed;
+
+ erl_init(NULL, 0);
+
+ while (read_cmd(buf) > 0) {
+ tuplep = erl_decode(buf);
+ fnp = erl_element(1, tuplep);
+ argp = erl_element(2, tuplep);
+
+ if (strncmp(ERL_ATOM_PTR(fnp), "foo", 3) == 0) {
+ res = foo(ERL_INT_VALUE(argp));
+ } else if (strncmp(ERL_ATOM_PTR(fnp), "bar", 17) == 0) {
+ res = bar(ERL_INT_VALUE(argp));
+ }
+
+ intp = erl_mk_int(res);
+ erl_encode(intp, buf);
+ write_cmd(buf, erl_term_len(intp));
+
+ erl_free_compound(tuplep);
+ erl_free_term(fnp);
+ erl_free_term(argp);
+ erl_free_term(intp);
+ }
+}
+