Compiling

Automatic defaults

If you compile Duktape with no compiler options, Duktape will detect the compiler and the platform automatically and select defaults appropriate in most cases. The default features are, at a high level:

Feature options (DUK_OPT_xxx)

If you wish to modify the defaults, you can provide feature options in the form of DUK_OPT_xxx compiler defines. These will be taken into account by the internal duk_features.h file, which resolves the final internal features based on feature requests, compiler features, and platform features.

The available feature options can be found in duk_features.h. The table below summarizes the available options (in no particular order):

Define Description
DUK_OPT_TRACEBACK_DEPTH Override default traceback collection depth. The default is currently 10.
DUK_OPT_NO_FILE_IO Disable use of ANSI C file I/O which might be a portability issue on some platforms. Causes e.g. duk_eval_file() to throw an error.
DUK_OPT_SEGFAULT_ON_PANIC Cause the default panic handler to cause a segfault instead of using abort() or exit(). This is useful when debugging with valgrind, as a segfault provides a nice C traceback in valgrind.
DUK_OPT_SELF_TESTS Perform run-time self tests when a Duktape heap is created. Catches platform/compiler problems which cannot be reliably detected during compile time.
DUK_OPT_DPRINT_COLORS Enable coloring of debug prints with ANSI escape codes. The behavior is not sensitive to terminal settings.
DUK_OPT_DPRINT_RDTSC Print RDTSC cycle count in debug prints if available.

DUK_PANIC_HANDLER

The default panic handler will print an error message to stdout (unless I/O is disabled by DUK_OPT_NO_FILE_IO). It will then call abort() (or cause a segfault if DUK_OPT_SEGFAULT_ON_PANIC is defined).

You can override the entire panic handler by defining DUK_PANIC_HANDLER on your own. You could add the following to your compiler options:

'-DDUK_PANIC_HANDLER(code,msg)={printf("*** %d:%s\n",(code),(msg));abort();}'

Or perhaps:

'-DDUK_PANIC_HANDLER(code,msg)={my_panic_handler((code),(msg))}'

which calls your custom handler:

void my_panic_handler(int code, const char *msg) {
    /* Your panic handling.  Must not return. */
}

Adding new feature options

This section only applies if you customize Duktape internals and wish to submit a patch to be included in the mainline distribution: