From 2326f05cb9b82b2d0afe2bd81e4c645c46c4e8eb Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Wed, 18 Sep 2013 14:34:14 +0300 Subject: [PATCH] remove test.c and use examples/hello instead --- README.txt.dist | 2 +- examples/Makefile.example | 4 ++-- examples/hello/hello.c | 35 +++++++++++++++++++++++++++++++++-- examples/test.c | 37 ------------------------------------- make_dist.sh | 1 - 5 files changed, 36 insertions(+), 43 deletions(-) delete mode 100644 examples/test.c diff --git a/README.txt.dist b/README.txt.dist index 7d510f75..249bdb3c 100644 --- a/README.txt.dist +++ b/README.txt.dist @@ -29,7 +29,7 @@ See Makefile.example for an example:: $ cd $ make -f Makefile.example [...] - $ ./test + $ ./hello Hello world! 2+3=5 diff --git a/examples/Makefile.example b/examples/Makefile.example index 0b55dd9b..72fffbf3 100644 --- a/examples/Makefile.example +++ b/examples/Makefile.example @@ -25,6 +25,6 @@ CCLIBS = -lm # For debugging, use -O0 -g -ggdb, and don't add -fomit-frame-pointer -test: $(DUKTAPE_SOURCES) test.c - $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) test.c $(CCLIBS) +hello: $(DUKTAPE_SOURCES) examples/hello/hello.c + $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) examples/hello/hello.c $(CCLIBS) diff --git a/examples/hello/hello.c b/examples/hello/hello.c index 5c4cb41b..7289af12 100644 --- a/examples/hello/hello.c +++ b/examples/hello/hello.c @@ -1,6 +1,37 @@ -#include +/* + * 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[]) { - /* 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; } + diff --git a/examples/test.c b/examples/test.c deleted file mode 100644 index 7289af12..00000000 --- a/examples/test.c +++ /dev/null @@ -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; -} - diff --git a/make_dist.sh b/make_dist.sh index 8cc82e6f..a5802d63 100644 --- a/make_dist.sh +++ b/make_dist.sh @@ -176,7 +176,6 @@ done for i in \ Makefile.example \ Makefile.cmdline \ - test.c \ ; do cp examples/$i $DIST/ done