Fork me on GitHub


Duktape is an embeddable Javascript engine, with a focus on portability and compact footprint.

Duktape is easy to integrate into a C/C++ project: add duktape.c, duktape.h, and duk_config.h to your build, and use the Duktape API to call Ecmascript functions from C code and vice versa.

Main features

Code and RAM footprint

 x86 defaultx86 lowmemx86 full lowmem
Startup RAM70kB45kB27kB

Full lowmem uses "pointer compression", Node.js Buffer and typed array support enabled.

Current status


Some projects using Duktape (alphabetical)

Some examples where and how Duktape is used:

If you're using Duktape in your project, send an e-mail or open a GitHub issue to be added to the list.

Similar engines

There are multiple Javascript engines targeting similar use cases as Duktape, at least:

Also see List of ECMAScript engines.

1 Add to build

(See Getting started for a more detailed introduction.)

Add Duktape C source and header to your build. Any build system can be used. The distributable contains an example Makefile for reference. In the simplest case:

$ gcc -std=c99 -o test test.c duktape.c -lm
$ ./test
Hello world!

2 Initialize a context

Initialize and use Duktape somewhere in your program:

/* test.c */
#include "duktape.h"

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

3 Add C function bindings

To call a C function from Ecmascript code, first declare your C function:

int adder(duk_context *ctx) {
  int i;
  int n = duk_get_top(ctx);  /* #args */
  double res = 0.0;

  for (i = 0; i < n; i++) {
    res += duk_to_number(ctx, i);

  duk_push_number(ctx, res);
  return 1;  /* one return value */

Register your function e.g. into the global object:

duk_push_c_function(ctx, adder, DUK_VARARGS);
duk_put_prop_string(ctx, -2 /*idx:global*/, "adder");
duk_pop(ctx);  /* pop global */

You can then call your function from Ecmascript code:

duk_eval_string(ctx, "print('2+3=' + adder(2, 3));");
duk_pop(ctx);  /* pop eval result */

Duktape is (C) by its authors and licensed under the MIT license.