Introduction

Version: XX.XX.XX (XXXX-XX-XX)

Document scope

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.

The API will be in flux until 1.0 release.

Searching for functions using browser search

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.

API safety

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.

Minimal Duktape program

#include "duktape.h"

int main(int argc, char *argv[]) {
    duk_context *ctx = duk_create_heap_default(ctx);
    if (ctx) {
        duk_eval_string(ctx, "print('Hello world from Javascript!');");
        duk_destroy_heap(ctx);
    }
    return 0;
}