Browse Source

remove test.c and use examples/hello instead

pull/1/head
Sami Vaarala 11 years ago
parent
commit
2326f05cb9
  1. 2
      README.txt.dist
  2. 4
      examples/Makefile.example
  3. 35
      examples/hello/hello.c
  4. 37
      examples/test.c
  5. 1
      make_dist.sh

2
README.txt.dist

@ -29,7 +29,7 @@ See Makefile.example for an example::
$ cd <dist_root> $ cd <dist_root>
$ make -f Makefile.example $ make -f Makefile.example
[...] [...]
$ ./test $ ./hello
Hello world! Hello world!
2+3=5 2+3=5

4
examples/Makefile.example

@ -25,6 +25,6 @@ CCLIBS = -lm
# For debugging, use -O0 -g -ggdb, and don't add -fomit-frame-pointer # For debugging, use -O0 -g -ggdb, and don't add -fomit-frame-pointer
test: $(DUKTAPE_SOURCES) test.c hello: $(DUKTAPE_SOURCES) examples/hello/hello.c
$(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) test.c $(CCLIBS) $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) examples/hello/hello.c $(CCLIBS)

35
examples/hello/hello.c

@ -1,6 +1,37 @@
#include <stdio.h> /*
* Very simple example program
*/
#include "duktape.h" #include "duktape.h"
int adder(duk_context *ctx) {
int i;
int n = duk_get_top(ctx); /* #args */
double res = 0.0;
for (i = 0; i < n; i++) {
res += duk_to_number(ctx, i);
}
duk_push_number(ctx, res);
return 1; /* one return value */
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
/* FIXME */ duk_context *ctx = duk_create_heap_default();
duk_eval_string(ctx, "print('Hello world!');");
duk_push_global_object(ctx);
duk_push_c_function(ctx, adder, DUK_VARARGS);
duk_put_prop_string(ctx, -2, "adder");
duk_pop(ctx); /* pop global */
duk_eval_string(ctx, "print('2+3=' + adder(2, 3));");
duk_pop(ctx); /* pop eval result */
duk_destroy_heap(ctx);
return 0;
} }

37
examples/test.c

@ -1,37 +0,0 @@
/*
* Very simple example program
*/
#include "duktape.h"
int adder(duk_context *ctx) {
int i;
int n = duk_get_top(ctx); /* #args */
double res = 0.0;
for (i = 0; i < n; i++) {
res += duk_to_number(ctx, i);
}
duk_push_number(ctx, res);
return 1; /* one return value */
}
int main(int argc, char *argv[]) {
duk_context *ctx = duk_create_heap_default();
duk_eval_string(ctx, "print('Hello world!');");
duk_push_global_object(ctx);
duk_push_c_function(ctx, adder, DUK_VARARGS);
duk_put_prop_string(ctx, -2, "adder");
duk_pop(ctx); /* pop global */
duk_eval_string(ctx, "print('2+3=' + adder(2, 3));");
duk_pop(ctx); /* pop eval result */
duk_destroy_heap(ctx);
return 0;
}

1
make_dist.sh

@ -176,7 +176,6 @@ done
for i in \ for i in \
Makefile.example \ Makefile.example \
Makefile.cmdline \ Makefile.cmdline \
test.c \
; do ; do
cp examples/$i $DIST/ cp examples/$i $DIST/
done done

Loading…
Cancel
Save