Browse Source

cleanup example: no more internal header use

pull/1/head
Sami Vaarala 11 years ago
parent
commit
03141d7d1f
  1. 17
      examples/cmdline/duk_cmdline.c
  2. 1
      examples/cmdline/duk_socket.c

17
examples/cmdline/duk_cmdline.c

@ -16,7 +16,6 @@
#include <readline/history.h>
#include "duktape.h"
#include "duk_internal.h"
#define MEM_LIMIT_NORMAL (128*1024*1024) /* 128 MB */
#define MEM_LIMIT_HIGH (2047*1024*1024) /* ~2 GB */
@ -65,18 +64,13 @@ static void set_sigint_handler(void) {
}
int wrapped_compile_execute(duk_context *ctx) {
duk_hthread *thr = (duk_hthread *) ctx;
int comp_flags;
/* FIXME: uses internal API */
comp_flags = 0;
duk_js_compile(thr, comp_flags);
duk_js_push_closure(thr,
(duk_hcompiledfunction *) duk_get_hobject(ctx, -1),
thr->builtins[DUK_BIDX_GLOBAL_ENV],
thr->builtins[DUK_BIDX_GLOBAL_ENV]);
duk_compile(ctx, comp_flags);
#if 0
/* FIXME: something similar with public API */
if (interactive_mode) {
duk_hcompiledfunction *f = (duk_hcompiledfunction *) duk_get_hobject(ctx, -1);
@ -92,6 +86,7 @@ int wrapped_compile_execute(duk_context *ctx) {
fflush(stdout);
}
}
#endif
duk_call(ctx, 0);
@ -136,7 +131,7 @@ int handle_fh(duk_context *ctx, FILE *f) {
interactive_mode = 0; /* global */
rc = duk_safe_call(ctx, wrapped_compile_execute, 1 /*nargs*/, 1 /*nret*/, DUK_INVALID_INDEX);
if (rc != DUK_ERR_EXEC_SUCCESS) {
if (rc != DUK_EXEC_SUCCESS) {
duk_to_string(ctx, -1);
fprintf(stderr, "Error: %s (rc=%d)\n", duk_get_string(ctx, -1), rc);
fflush(stderr);
@ -222,7 +217,7 @@ int handle_interactive(duk_context *ctx) {
interactive_mode = 1; /* global */
rc = duk_safe_call(ctx, wrapped_compile_execute, 1 /*nargs*/, 1 /*nret*/, DUK_INVALID_INDEX);
if (rc != DUK_ERR_EXEC_SUCCESS) {
if (rc != DUK_EXEC_SUCCESS) {
duk_to_string(ctx, -1);
/* in interactive mode, write to stdout */

1
examples/cmdline/duk_socket.c

@ -2,6 +2,7 @@
* TCP sockets binding example.
*/
#define _GNU_SOURCE
#include <errno.h>
#include <string.h>
#include <stdio.h>

Loading…
Cancel
Save