This section summarizes some commonly needed header definitions in
duktape.h
. It is not exhaustive and the excerpts have been
reorganized for readability. Don't rely on specific define values, only
the define names. When in doubt, consult the header directly.
Duktape version is available through the DUK_VERSION
define:
DUK_VERSION |
Numeric value (major * 10000 + minor * 100 + patch) |
For example, version 2.3.4 would have the value 20304. The same value is
available to ECMAScript code through Duktape.version
.
For pre-releases DUK_VERSION
is one less than the actual
release, e.g. 2.4.0 pre-release would be 20399. See
Versioning.
The following Git identifiers are available (all refer to the Duktape GitHub repo):
DUK_GIT_DESCRIBE |
Git describe string for the Duktape build. For official releases this is just "v1.0.0" or similar, but for snapshot builds it provides useful version information, e.g. "v1.0.0-155-g5b7ef1f-dirty". |
DUK_GIT_COMMIT |
Exact commit hash where distributable was built from. |
DUK_GIT_BRANCH |
Branch where the distributable was built from. This is useful to identify prototypes built from a development branch. |
There are no equivalent defines in the ECMAScript environment.
Debug protocol version number:
DUK_DEBUG_PROTOCOL_VERSION |
Version number of the debug protocol (a single integer) |
typedef struct duk_hthread duk_context; typedef duk_ret_t (*duk_c_function)(duk_context *ctx); typedef void *(*duk_alloc_function) (void *udata, duk_size_t size); typedef void *(*duk_realloc_function) (void *udata, void *ptr, duk_size_t size); typedef void (*duk_free_function) (void *udata, void *ptr); typedef void (*duk_fatal_function) (void *udata, const char *msg); typedef void (*duk_decode_char_function) (void *udata, duk_codepoint_t codepoint); typedef duk_codepoint_t (*duk_map_char_function) (void *udata, duk_codepoint_t codepoint); typedef duk_ret_t (*duk_safe_call_function) (duk_context *ctx, void *udata); typedef duk_size_t (*duk_debug_read_function) (void *udata, char *buffer, duk_size_t length); typedef duk_size_t (*duk_debug_write_function) (void *udata, const char *buffer, duk_size_t length); typedef duk_size_t (*duk_debug_peek_function) (void *udata); typedef void (*duk_debug_read_flush_function) (void *udata); typedef void (*duk_debug_write_flush_function) (void *udata); typedef void (*duk_debug_detached_function) (duk_context *ctx, void *udata); struct duk_memory_functions { duk_alloc_function alloc_func; duk_realloc_function realloc_func; duk_free_function free_func; void *udata; }; typedef struct duk_memory_functions duk_memory_functions; struct duk_function_list_entry { const char *key; duk_c_function value; duk_int_t nargs; }; typedef struct duk_function_list_entry duk_function_list_entry; struct duk_number_list_entry { const char *key; duk_double_t value; }; typedef struct duk_number_list_entry duk_number_list_entry;
Error codes used by e.g. duk_error():
DUK_ERR_NONE |
No error, e.g. from duk_get_error_code() |
DUK_ERR_ERROR |
Error |
DUK_ERR_EVAL_ERROR |
EvalError |
DUK_ERR_RANGE_ERROR |
RangeError |
DUK_ERR_REFERENCE_ERROR |
ReferenceError |
DUK_ERR_SYNTAX_ERROR |
SyntaxError |
DUK_ERR_TYPE_ERROR |
TypeError |
DUK_ERR_URI_ERROR |
URIError |
Shorthand return values for Duktape/C functions, e.g.
return DUK_RET_TYPE_ERROR
is similar to calling
duk_type_error()
but shorter:
DUK_RET_ERROR |
Similar to throwing with DUK_ERR_ERROR |
DUK_RET_EVAL_ERROR |
Similar to throwing with DUK_ERR_EVAL_ERROR |
DUK_RET_RANGE_ERROR |
Similar to throwing with DUK_ERR_RANGE_ERROR |
DUK_RET_REFERENCE_ERROR |
Similar to throwing with DUK_ERR_REFERENCE_ERROR |
DUK_RET_SYNTAX_ERROR |
Similar to throwing with DUK_ERR_SYNTAX_ERROR |
DUK_RET_TYPE_ERROR |
Similar to throwing with DUK_ERR_TYPE_ERROR |
DUK_RET_URI_ERROR |
Similar to throwing with DUK_ERR_URI_ERROR |
Return codes for protected calls (e.g. duk_safe_call(), duk_pcall()):
DUK_EXEC_SUCCESS |
Call finished without error |
DUK_EXEC_ERROR |
Call failed, error was caught |
Compilation flags for e.g. duk_compile() and duk_eval():
DUK_COMPILE_EVAL |
Compile eval code (instead of program) |
DUK_COMPILE_FUNCTION |
Compile function code (instead of program) |
DUK_COMPILE_STRICT |
Use strict (outer) context for program, eval, or function |
Flags for duk_def_prop() and its variants:
DUK_DEFPROP_WRITABLE |
Set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set) |
DUK_DEFPROP_ENUMERABLE |
Set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set) |
DUK_DEFPROP_CONFIGURABLE |
Set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set) |
DUK_DEFPROP_HAVE_WRITABLE |
Set/clear writable |
DUK_DEFPROP_HAVE_ENUMERABLE |
Set/clear enumerable |
DUK_DEFPROP_HAVE_CONFIGURABLE |
Set/clear configurable |
DUK_DEFPROP_HAVE_VALUE |
Set value (given on value stack) |
DUK_DEFPROP_HAVE_GETTER |
Set getter (given on value stack) |
DUK_DEFPROP_HAVE_SETTER |
Set setter (given on value stack) |
DUK_DEFPROP_FORCE |
Force change if possible, may still fail for e.g. virtual properties |
DUK_DEFPROP_SET_WRITABLE |
(DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_WRITABLE) |
DUK_DEFPROP_CLEAR_WRITABLE |
DUK_DEFPROP_HAVE_WRITABLE |
DUK_DEFPROP_SET_ENUMERABLE |
(DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE) |
DUK_DEFPROP_CLEAR_ENUMERABLE |
DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_SET_CONFIGURABLE |
(DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_CONFIGURABLE) |
DUK_DEFPROP_CLEAR_CONFIGURABLE |
DUK_DEFPROP_HAVE_CONFIGURABLE |
Some convenience variants omitted, see
duk_def_prop()
.
Enumeration flags for duk_enum():
DUK_ENUM_INCLUDE_NONENUMERABLE |
Enumerate non-numerable properties in addition to enumerable |
DUK_ENUM_INCLUDE_HIDDEN |
Enumerate hidden Symbols too (in Duktape 1.x called internal properties) |
DUK_ENUM_INCLUDE_SYMBOLS |
Enumerate Symbol keys (default is not to enumerate them) |
DUK_ENUM_EXCLUDE_STRINGS |
Do not enumerate string keys (default is to enumerate them) |
DUK_ENUM_OWN_PROPERTIES_ONLY |
Don't walk prototype chain, only check own properties |
DUK_ENUM_ARRAY_INDICES_ONLY |
Only enumerate array indices |
DUK_ENUM_SORT_ARRAY_INDICES |
Sort array indices (applied to full enumeration result, including inherited array indices) |
DUK_ENUM_NO_PROXY_BEHAVIOR |
Enumerate a proxy object itself without invoking proxy behavior |
Flags for duk_gc():
DUK_GC_COMPACT |
Compact heap objects |
Coercion hints:
DUK_HINT_NONE |
Prefer number, unless coercion input is a Date, in which case prefer string (E5 Section 8.12.8) |
DUK_HINT_STRING |
Prefer string |
DUK_HINT_NUMBER |
Prefer number |
The following macros are defined for creating internal Symbol representations as C literals. All arguments must be string literals and cannot be computed values:
DUK_HIDDEN_SYMBOL(x) |
A C literal for a Duktape specific hidden Symbol |
DUK_GLOBAL_SYMBOL(x) |
A C literal for a global symbol, equivalent to Symbol.for(x) |
DUK_LOCAL_SYMBOL(x,uniq) |
A C literal for a local symbol, equivalent to Symbol(x) ,
unique part provided in 'uniq' must not conflict with Duktape internal
format, recommendation is to prefix the unique part with a "!" |
DUK_WELLKNOWN_SYMBOL(x) |
A C literal for a well-known symbol like Symbol.iterator |
DUK_INTERNAL_SYMBOL(x) |
A C literal for a Duktape internal symbol; an application shouldn't normally use this macro at all, it is reserved for Duktape internal symbols only (with no versioning guarantees) |
DUK_INVALID_INDEX |
Stack index is invalid, missing, or n/a |
DUK_VARARGS |
Function takes variable arguments |
DUK_API_ENTRY_STACK |
Number of value stack entries guaranteed to be reserved at function entry |