Browse Source

Merge pull request #678 from svaarala/replace-readline-in-examples

Replace readline with Linenoise in examples
pull/682/head
Sami Vaarala 9 years ago
parent
commit
01f93412a3
  1. 112
      .gitignore
  2. 50
      Makefile
  3. 5
      RELEASES.rst
  4. 14
      dist-files/Makefile.cmdline
  5. 143
      examples/cmdline/duk_cmdline.c
  6. 4
      website/guide/compiling.html
  7. 12
      website/guide/gettingstarted.html

112
.gitignore

@ -2,58 +2,60 @@
*.swp
*.o
*.strip
build/
dist/
site/
stuff/
autotest/
duktape-releases/
doc/*.pdf
src/*.pyc
UglifyJS/
UglifyJS2/
closure-compiler/
emscripten/
underscore/
lodash/
test262-d067d2f0ca30/
test262-es5-tests/
es5-tests.zip
JS-Interpreter/
runtests/node_modules/
d067d2f0ca30.tar.bz2
595a36b252ee97110724e6fa89fc92c9aa9a206a.zip
regfuzz-0.1.tar.gz
compiler-latest.zip
compiler.jar
cloc-1.60.pl
lua-5.2.3.tar.gz
luajs.zip
bluebird.js
dukvm.js
jquery-1.11.0.js
coffee-script
LiveScript
coco
sax-js
xmldoc
FlameGraph
dtrace4linux
flow
massif-*.out
ms_print.*
alljoyn-js
ajtcl
dukweb.js
debugger/jquery-ui-1.11.2.zip
debugger/jquery-ui-1.11.2/
debugger/node_modules/
debugger/static/images/
debugger/static/jquery-1.11.1.min.js
debugger/static/jquery-ui.min.css
debugger/static/jquery-ui.min.js
debugger/static/reset.css
debugger/static/socket.io-1.2.0.js
references/ECMA-262 5th edition December 2009.pdf
references/ECMA-262 5.1 edition June 2011.pdf
references/ECMA-262.pdf
/duk.O2.*
/build/
/dist/
/site/
/stuff/
/autotest/
/duktape-releases/
/doc/*.pdf
/src/*.pyc
/UglifyJS/
/UglifyJS2/
/closure-compiler/
/linenoise/
/emscripten/
/underscore/
/lodash/
/test262-d067d2f0ca30/
/test262-es5-tests/
/es5-tests.zip
/JS-Interpreter/
/runtests/node_modules/
/d067d2f0ca30.tar.bz2
/595a36b252ee97110724e6fa89fc92c9aa9a206a.zip
/regfuzz-0.1.tar.gz
/compiler-latest.zip
/compiler.jar
/cloc-1.60.pl
/lua-5.2.3.tar.gz
/luajs.zip
/bluebird.js
/dukvm.js
/jquery-1.11.0.js
/coffee-script
/LiveScript
/coco
/sax-js
/xmldoc
/FlameGraph
/dtrace4linux
/flow
/massif-*.out
/ms_print.*
/alljoyn-js
/ajtcl
/dukweb.js
/debugger/jquery-ui-1.11.2.zip
/debugger/jquery-ui-1.11.2/
/debugger/node_modules/
/debugger/static/images/
/debugger/static/jquery-1.11.1.min.js
/debugger/static/jquery-ui.min.css
/debugger/static/jquery-ui.min.js
/debugger/static/reset.css
/debugger/static/socket.io-1.2.0.js
/references/ECMA-262 5th edition December 2009.pdf
/references/ECMA-262 5.1 edition June 2011.pdf
/references/ECMA-262.pdf

50
Makefile

@ -172,6 +172,8 @@ DUKTAPE_CMDLINE_SOURCES = \
dist/examples/alloc-torture/duk_alloc_torture.c \
dist/examples/alloc-hybrid/duk_alloc_hybrid.c \
dist/examples/debug-trans-socket/duk_trans_socket_unix.c
LINENOISE_SOURCES = \
linenoise/linenoise.c
# Compiler setup for Linux
CC = gcc
@ -265,6 +267,7 @@ CCOPTS_FEATURES += -DDUK_CMDLINE_DEBUGGER_SUPPORT
CCOPTS_FEATURES += -DDUK_CMDLINE_FILEIO
CCOPTS_SHARED =
CCOPTS_SHARED += -D_POSIX_C_SOURCE=200809L # to avoid linenoise strdup() warnings
CCOPTS_SHARED += -pedantic -ansi -std=c99 -fstrict-aliasing
# -Wextra is very picky but catches e.g. signed/unsigned comparisons
CCOPTS_SHARED += -Wall -Wextra -Wunused-result
@ -272,7 +275,7 @@ CCOPTS_SHARED += -Wcast-qual
CCOPTS_SHARED += -Wunreachable-code # on some compilers unreachable code is an error
# -Wfloat-equal is too picky, there's no apparent way to compare floats
# (even when you know it's safe) without triggering warnings
CCOPTS_SHARED += -I./dist/src -I./dist/examples/alloc-logging -I./dist/examples/alloc-torture -I./dist/examples/alloc-hybrid -I./dist/examples/debug-trans-socket
CCOPTS_SHARED += -I./dist/src -I./linenoise -I./dist/examples/alloc-logging -I./dist/examples/alloc-torture -I./dist/examples/alloc-hybrid -I./dist/examples/debug-trans-socket
#CCOPTS_SHARED += -I./dist/src-separate
#CCOPTS_SHARED += -m32 # force 32-bit compilation on a 64-bit host
#CCOPTS_SHARED += -mx32 # force X32 compilation on a 64-bit host
@ -300,8 +303,6 @@ GXXOPTS_DEBUG += -DDUK_OPT_DEBUG -DDUK_OPT_DPRINT -DDUK_OPT_ASSERTIONS -DDUK_OPT
#GXXOPTS_DEBUG += -DDUK_OPT_DDPRINT -DDUK_OPT_DDDPRINT
CCLIBS = -lm
CCLIBS += -lreadline
CCLIBS += -lncurses # on some systems -lreadline also requires -lncurses (e.g. RHEL)
# Replace 'duk' and 'dukd' with automatic valgrind wrappers (plain commands
# will be duk.raw and dukd.raw). Targets for runtests.js bypass the wrapper
@ -359,6 +360,7 @@ cleanall: clean
# Don't delete these in 'clean' to avoid re-downloading them over and over
@rm -rf duktape-releases
@rm -f regfuzz-*.tar.gz
@rm -rf linenoise
@rm -rf UglifyJS
@rm -rf UglifyJS2
@rm -rf closure-compiler
@ -402,32 +404,32 @@ libduktaped.so.1.0.0: dist
ln -s $@ $(subst .so.1.0.0,.so.1,$@)
ln -s $@ $(subst .so.1.0.0,.so,$@)
duk.raw: dist
$(CC) -o $@ $(CCOPTS_NONDEBUG) $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)
duk.raw: dist linenoise
$(CC) -o $@ $(CCOPTS_NONDEBUG) $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(LINENOISE_SOURCES) $(CCLIBS)
-@size $@
duk-clang: dist
duk-clang: dist linenoise
# Use -Wcast-align to trigger issues like: https://github.com/svaarala/duktape/issues/270
clang -o $@ -Wcast-align $(CCOPTS_NONDEBUG) $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)
clang -o $@ -Wcast-align $(CCOPTS_NONDEBUG) $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(LINENOISE_SOURCES) $(CCLIBS)
-@size $@
duk.O2: dist
$(CC) -o $@ $(CCOPTS_NONDEBUG) -O2 $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)
duk.O2: dist linenoise
$(CC) -o $@ $(CCOPTS_NONDEBUG) -O2 $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(LINENOISE_SOURCES) $(CCLIBS)
-@size $@
duk.O3: dist
$(CC) -o $@ $(CCOPTS_NONDEBUG) -O3 $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)
duk.O3: dist linenoise
$(CC) -o $@ $(CCOPTS_NONDEBUG) -O3 $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(LINENOISE_SOURCES) $(CCLIBS)
-@size $@
duk.O4: dist
$(CC) -o $@ $(CCOPTS_NONDEBUG) -O4 $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)
duk.O4: dist linenoise
$(CC) -o $@ $(CCOPTS_NONDEBUG) -O4 $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(LINENOISE_SOURCES) $(CCLIBS)
-@size $@
# Test target for g++ compile
duk-g++: dist
duk-g++: dist linenoise
$(GXX) -o $@ $(GXXOPTS_NONDEBUG) $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)
-@size $@
dukd-g++: dist
dukd-g++: dist linenoise
$(GXX) -o $@ $(GXXOPTS_DEBUG) $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)
-@size $@
@ -451,8 +453,8 @@ else
@cp duk.raw $@
endif
dukd.raw: dist
$(CC) -o $@ $(CCOPTS_DEBUG) $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)
dukd.raw: dist linenoise
$(CC) -o $@ $(CCOPTS_DEBUG) $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(LINENOISE_SOURCES) $(CCLIBS)
-@size $@
dukd.vg: dukd.raw
@ -484,11 +486,11 @@ issuecount:
.PHONY: dukscanbuild
dukscanbuild: dist
scan-build gcc -o/tmp/duk.scanbuild -Idist/src-separate/ $(CCOPTS_NONDEBUG) $(DUKTAPE_SOURCES_SEPARATE) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)
scan-build gcc -o/tmp/duk.scanbuild -Idist/src-separate/ $(CCOPTS_NONDEBUG) $(DUKTAPE_SOURCES_SEPARATE) $(DUKTAPE_CMDLINE_SOURCES) $(LINENOISE_SOURCES) $(CCLIBS)
.PHONY: dukdscanbuild
dukdscanbuild: dist
scan-build gcc -o/tmp/duk.scanbuild -Idist/src-separate/ $(CCOPTS_DEBUG) $(DUKTAPE_SOURCES_SEPARATE) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)
scan-build gcc -o/tmp/duk.scanbuild -Idist/src-separate/ $(CCOPTS_DEBUG) $(DUKTAPE_SOURCES_SEPARATE) $(DUKTAPE_CMDLINE_SOURCES) $(LINENOISE_SOURCES) $(CCLIBS)
.PHONY: test
test: qecmatest apitest regfuzztest underscoretest lodashtest emscriptentest emscripteninceptiontest test262test
@ -562,6 +564,12 @@ matrix1000: dist
matrix10000: dist
cd dist; $(PYTHON) ../util/matrix_compile.py --count=10000
linenoise:
# git clone https://github.com/antirez/linenoise.git
# Use forked repo to get compile warnings fixed (not yet fixed in
# linenoise master).
git clone -b fix-compile-warnings https://github.com/svaarala/linenoise.git
regfuzz-0.1.tar.gz:
# https://code.google.com/p/regfuzz/
# SHA1: 774be8e3dda75d095225ba699ac59969d92ac970
@ -991,7 +999,7 @@ CCOPTS_AJDUK += '-DDUK_OPT_DECLARE=extern uint8_t *ajsheap_ram; extern duk_uint1
# Command line with Alljoyn.js pool allocator, for low memory testing.
# The pool sizes only make sense with -m32, so force that. This forces
# us to use barebones cmdline too.
ajduk: alljoyn-js ajtcl dist
ajduk: alljoyn-js ajtcl dist linenoise
$(CC) -o $@ \
-Ialljoyn-js/src -Iajtcl/inc/ -Iajtcl/src/target/linux/ \
$(CCOPTS_NONDEBUG) \
@ -1002,7 +1010,7 @@ ajduk: alljoyn-js ajtcl dist
-lm -lpthread
@echo "*** SUCCESS:"
@ls -l ajduk
ajdukd: alljoyn-js ajtcl dist
ajdukd: alljoyn-js ajtcl dist linenoise
$(CC) -o $@ \
-Ialljoyn-js/src -Iajtcl/inc/ -Iajtcl/src/target/linux/ \
$(CCOPTS_DEBUG) \

5
RELEASES.rst

@ -1506,6 +1506,11 @@ Planned
* Change OS string (visible in Duktape.env) from "ios" to "osx" for non-phone
targets (GH-570, GH-571)
* Remove readline support from duk_cmdline.c ('duk' command line tool), add
support for Linenoise instead; -DDUK_CMDLINE_FANCY now assumes linenoise.h
is in the include path and that linenoise.c is compiled with the command
line tool (or linked from a library) (GH-678)
* Internal performance improvement: use raw value stack accessors internally
when it's safe to do so (GH-582)

14
dist-files/Makefile.cmdline

@ -13,12 +13,12 @@ CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer
CCOPTS += -I./src # duktape.h and duk_config.h must be in include path
CCLIBS = -lm
# If you have readline, you may want to enable these. On some platforms
# -lreadline also requires -lncurses (e.g. RHEL), so it is added by default
# (you may be able to remove it)
# If you want linenoise, you can enable these. At the moment linenoise
# will cause some harmless compilation warnings.
#CCOPTS += -DDUK_CMDLINE_FANCY
#CCLIBS += -lreadline
#CCLIBS += -lncurses
#DUKTAPE_CMDLINE_SOURCES += linenoise/linenoise.c
#CCOPTS += -I./linenoise
#duk: linenoise
# Optional feature defines, see: http://duktape.org/guide.html#compiling
CCOPTS += -DDUK_OPT_SELF_TESTS
@ -26,5 +26,9 @@ CCOPTS += -DDUK_OPT_SELF_TESTS
#CCOPTS += -DDUK_OPT_DPRINT
# ...
linenoise/linenoise.c: linenoise
linenoise:
git clone https://github.com/antirez/linenoise.git
duk: $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES)
$(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(DUKTAPE_CMDLINE_SOURCES) $(CCLIBS)

143
examples/cmdline/duk_cmdline.c

@ -1,15 +1,16 @@
/*
* Command line execution tool. Useful for test cases and manual testing.
*
* To enable readline and other fancy stuff, compile with -DDUK_CMDLINE_FANCY.
* To enable linenoise and other fancy stuff, compile with -DDUK_CMDLINE_FANCY.
* It is not the default to maximize portability. You can also compile in
* support for example allocators, grep for DUK_CMDLINE_*.
*/
#if !defined(DUK_CMDLINE_FANCY)
#define NO_READLINE
#define NO_RLIMIT
#define NO_SIGNAL
/* Helper define to enable a feature set; can also use separate defines. */
#if defined(DUK_CMDLINE_FANCY)
#define DUK_CMDLINE_LINENOISE
#define DUK_CMDLINE_RLIMIT
#define DUK_CMDLINE_SIGNAL
#endif
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \
@ -36,15 +37,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !defined(NO_SIGNAL)
#if defined(DUK_CMDLINE_SIGNAL)
#include <signal.h>
#endif
#if !defined(NO_RLIMIT)
#if defined(DUK_CMDLINE_RLIMIT)
#include <sys/resource.h>
#endif
#if !defined(NO_READLINE)
#include <readline/readline.h>
#include <readline/history.h>
#if defined(DUK_CMDLINE_LINENOISE)
#include "linenoise.h"
#endif
#if defined(DUK_CMDLINE_FILEIO)
#include <errno.h>
@ -98,7 +98,7 @@ static int debugger_reattach = 0;
* Misc helpers
*/
#if !defined(NO_RLIMIT)
#if defined(DUK_CMDLINE_RLIMIT)
static void set_resource_limits(rlim_t mem_limit_value) {
int rc;
struct rlimit lim;
@ -127,9 +127,9 @@ static void set_resource_limits(rlim_t mem_limit_value) {
fprintf(stderr, "Set RLIMIT_AS to %d\n", (int) mem_limit_value);
#endif
}
#endif /* NO_RLIMIT */
#endif /* DUK_CMDLINE_RLIMIT */
#if !defined(NO_SIGNAL)
#if defined(DUK_CMDLINE_SIGNAL)
static void my_sighandler(int x) {
fprintf(stderr, "Got signal %d\n", x);
fflush(stderr);
@ -138,7 +138,7 @@ static void set_sigint_handler(void) {
(void) signal(SIGINT, my_sighandler);
(void) signal(SIGPIPE, SIG_IGN); /* avoid SIGPIPE killing process */
}
#endif /* NO_SIGNAL */
#endif /* DUK_CMDLINE_SIGNAL */
static int get_stack_raw(duk_context *ctx) {
if (!duk_is_object(ctx, -1)) {
@ -486,50 +486,36 @@ static int handle_eval(duk_context *ctx, char *code) {
return retval;
}
#if defined(NO_READLINE)
#if defined(DUK_CMDLINE_LINENOISE)
static int handle_interactive(duk_context *ctx) {
const char *prompt = "duk> ";
char *buffer = NULL;
int retval = 0;
int rc;
int got_eof = 0;
duk_eval_string(ctx, GREET_CODE(" [no readline]"));
duk_eval_string(ctx, GREET_CODE(" [linenoise]"));
duk_pop(ctx);
buffer = (char *) malloc(LINEBUF_SIZE);
if (!buffer) {
fprintf(stderr, "failed to allocated a line buffer\n");
fflush(stderr);
retval = -1;
goto done;
}
linenoiseSetMultiLine(1);
linenoiseHistorySetMaxLen(64);
while (!got_eof) {
size_t idx = 0;
for (;;) {
if (buffer) {
linenoiseFree(buffer);
buffer = NULL;
}
fwrite(prompt, 1, strlen(prompt), stdout);
fflush(stdout);
buffer = linenoise(prompt);
if (!buffer) {
break;
}
for (;;) {
int c = fgetc(stdin);
if (c == EOF) {
got_eof = 1;
break;
} else if (c == '\n') {
break;
} else if (idx >= LINEBUF_SIZE) {
fprintf(stderr, "line too long\n");
fflush(stderr);
retval = -1;
goto done;
} else {
buffer[idx++] = (char) c;
}
if (buffer && buffer[0] != (char) 0) {
linenoiseHistoryAdd(buffer);
}
duk_push_pointer(ctx, (void *) buffer);
duk_push_uint(ctx, (duk_uint_t) idx);
duk_push_uint(ctx, (duk_uint_t) strlen(buffer));
duk_push_string(ctx, "input");
interactive_mode = 1; /* global */
@ -540,6 +526,11 @@ static int handle_interactive(duk_context *ctx) {
ajsheap_clear_exec_timeout();
#endif
if (buffer) {
linenoiseFree(buffer);
buffer = NULL;
}
if (rc != DUK_EXEC_SUCCESS) {
/* in interactive mode, write to stdout */
print_pop_error(ctx, stdout);
@ -549,49 +540,57 @@ static int handle_interactive(duk_context *ctx) {
}
}
done:
if (buffer) {
free(buffer);
linenoiseFree(buffer);
buffer = NULL;
}
return retval;
}
#else /* NO_READLINE */
#else /* DUK_CMDLINE_LINENOISE */
static int handle_interactive(duk_context *ctx) {
const char *prompt = "duk> ";
char *buffer = NULL;
int retval = 0;
int rc;
int got_eof = 0;
duk_eval_string(ctx, GREET_CODE(""));
duk_pop(ctx);
/*
* Note: using readline leads to valgrind-reported leaks inside
* readline itself. Execute code from an input file (and not
* through stdin) for clean valgrind runs.
*/
rl_initialize();
buffer = (char *) malloc(LINEBUF_SIZE);
if (!buffer) {
fprintf(stderr, "failed to allocated a line buffer\n");
fflush(stderr);
retval = -1;
goto done;
}
for (;;) {
if (buffer) {
free(buffer);
buffer = NULL;
}
while (!got_eof) {
size_t idx = 0;
buffer = readline(prompt);
if (!buffer) {
break;
}
fwrite(prompt, 1, strlen(prompt), stdout);
fflush(stdout);
if (buffer && buffer[0] != (char) 0) {
add_history(buffer);
for (;;) {
int c = fgetc(stdin);
if (c == EOF) {
got_eof = 1;
break;
} else if (c == '\n') {
break;
} else if (idx >= LINEBUF_SIZE) {
fprintf(stderr, "line too long\n");
fflush(stderr);
retval = -1;
goto done;
} else {
buffer[idx++] = (char) c;
}
}
duk_push_pointer(ctx, (void *) buffer);
duk_push_uint(ctx, (duk_uint_t) strlen(buffer));
duk_push_uint(ctx, (duk_uint_t) idx);
duk_push_string(ctx, "input");
interactive_mode = 1; /* global */
@ -602,11 +601,6 @@ static int handle_interactive(duk_context *ctx) {
ajsheap_clear_exec_timeout();
#endif
if (buffer) {
free(buffer);
buffer = NULL;
}
if (rc != DUK_EXEC_SUCCESS) {
/* in interactive mode, write to stdout */
print_pop_error(ctx, stdout);
@ -616,6 +610,7 @@ static int handle_interactive(duk_context *ctx) {
}
}
done:
if (buffer) {
free(buffer);
buffer = NULL;
@ -623,7 +618,7 @@ static int handle_interactive(duk_context *ctx) {
return retval;
}
#endif /* NO_READLINE */
#endif /* DUK_CMDLINE_LINENOISE */
/*
* Simple file read/write bindings
@ -1037,7 +1032,7 @@ int main(int argc, char *argv[]) {
* Signal handling setup
*/
#if !defined(NO_SIGNAL)
#if defined(DUK_CMDLINE_SIGNAL)
set_sigint_handler();
/* This is useful at the global level; libraries should avoid SIGPIPE though */
@ -1109,7 +1104,7 @@ int main(int argc, char *argv[]) {
* Memory limit
*/
#if !defined(NO_RLIMIT)
#if defined(DUK_CMDLINE_RLIMIT)
set_resource_limits(memlimit_high ? MEM_LIMIT_HIGH : MEM_LIMIT_NORMAL);
#else
if (memlimit_high == 0) {

4
website/guide/compiling.html

@ -250,7 +250,7 @@ C++ toolchain. At least when mixing gcc/g++ you may encounter something like:</
<pre>
$ g++ -c -o duktape.o -Isrc/ src/duktape.c
$ gcc -c -o duk_cmdline.o -Isrc/ examples/cmdline/duk_cmdline.c
$ gcc -o duk duktape.o duk_cmdline.o -lm -lreadline -lncurses
$ gcc -o duk duktape.o duk_cmdline.o -lm
duktape.o:(.eh_frame+0x1ab): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
</pre>
@ -259,7 +259,7 @@ collect2: error: ld returned 1 exit status
<pre>
$ g++ -c -o duktape.o -Isrc/ src/duktape.c
$ gcc -c -o duk_cmdline.o -Isrc/ examples/cmdline/duk_cmdline.c
$ g++ -o duk duktape.o duk_cmdline.o -lm -lreadline -lncurses
$ g++ -o duk duktape.o duk_cmdline.o -lm
</pre>
<p>Because <code>duktape.h</code> selects C/C++ data types needed by

12
website/guide/gettingstarted.html

@ -26,19 +26,21 @@ quite simple).
</div>
<div class="note">
The command line tool avoids platform dependencies by default. If you're running a
UNIX variant and have <code>readline</code> and the necessary development headers,
you can enable line editing support by editing the Makefile:
The command line tool avoids platform dependencies by default. You can add
line editing support via <a href="https://github.com/antirez/linenoise">linenoise</a>
by editing the Makefile:
<ul>
<li>Add <code class="nobreak">-DDUK_CMDLINE_FANCY</code></li>
<li>Add <code>-lreadline</code> and <code>-lncurses</code></li>
<li>Add <code>-Ipath/to/linenoise</code> for the <code>linenoise.h</code> header</li>
<li>Add <code>path/to/linenoise.c</code> to the source list</li>
<li>Note: linenoise only works for POSIX environments using a C compiler (not C++)</li>
</ul>
</div>
<p>You can now run Ecmascript code interactively:</p>
<pre>
$ ./duk
((o) Duktape [no readline] 1.4.0 (v1.4.0)
((o) Duktape 1.4.0 (v1.4.0)
duk&gt; print('Hello world!')
Hello world!
= undefined

Loading…
Cancel
Save