Version: XX.XX.XX (XXXX-XX-XX)
The Duktape API (defined in duktape.h
) is a set of constants
and API calls which allows C/C++ programs to interface with Ecmascript
code and shields them from internal details like value representation.
This document provides a concise reference for the Duktape API and its core concepts. If you're new to Duktape, please read the Duktape Programmer's Guide first.
You can use browser search (typically CTRL-F) to search for
function definitions by prepending a dot to the search term. For instance,
use ".duk_example_func" to look for duk_example_func()
. In most
browsers only the actual section defining the function should be found.
As a general rule, API calls check all their parameters and tolerate
NULL
arguments and invalid value stack indices without unsafe
behavior (crashes).
One major exception is the Duktape context argument, ctx
.
Unless stated otherwise, it is not checked and is required to be
non-NULL
or unsafe behavior may occur. This is the case
because explicit checks for the argument would increase code footprint
for little practical gain.
Also see Error handling best practices, especially to avoid uncaught errors which lead to difficult to diagnose fatal errors.
All Duktape API calls are potentially macros. The implementation of a certain API call may change between a macro and an actual function even between compatible releases. See Duktape API for more discussion.
#include "duktape.h" int main(int argc, char *argv[]) { duk_context *ctx = duk_create_heap_default(); if (ctx) { duk_eval_string(ctx, "print('Hello world from Javascript!');"); duk_destroy_heap(ctx); } return 0; }