Duktape
By the Duktape project
Duktape is an embeddable JavaScript engine written in portable C, designed to be dropped into applications and embedded systems that need a small, self-contained scripting layer. It distributes as a small set of C source and header files…
Definition
Duktape is an embeddable JavaScript engine written in portable C, designed to be dropped into applications and embedded systems that need a small, self-contained scripting layer. It distributes as a small set of C source and header files rather than a system library, making it a common choice for adding scripting to native applications, games, and firmware running on constrained hardware.
Overview
Duktape was created to fill a gap left by browser-oriented JavaScript engines such as V8 and SpiderMonkey, which are large, complex codebases tuned for desktop and server performance rather than for easy embedding in a small native application. Its design goal from the outset was footprint and portability: a C programmer should be able to add a small number of files to a project and get a working JavaScript interpreter without pulling in a large build system or platform-specific dependencies. Mechanically, Duktape compiles JavaScript source into a compact bytecode format and executes it with a register-based virtual machine written in ANSI C, which keeps memory use and binary size low compared with JIT-compiling engines. It exposes a stack-based C API, modeled loosely on the design of the Lua scripting language's API, for passing values and calling functions between native code and JavaScript. This makes the boundary between host application and script explicit and easy to reason about, at the cost of the raw execution speed that a JIT compiler would provide. Among embeddable scripting options, Duktape occupies a niche similar to Lua but for teams that specifically want JavaScript syntax and semantics rather than a different embedded language. Compared with heavier engines like V8, GraalJS, or even Boa, Duktape trades peak execution speed for a dramatically smaller footprint and simpler integration, which matters more on memory-constrained targets than on servers or desktops. In practice, Duktape is used to add user-scriptable behavior to games, to implement configuration or automation logic in embedded and IoT devices, and to give native applications a lightweight way to run user-supplied or plugin JavaScript without linking against a full browser engine. Its small footprint makes it viable on microcontrollers and other resource-limited targets where V8 or similar engines would be impractical. The main trade-off with Duktape is performance: because it interprets bytecode without a just-in-time compiler, computationally heavy JavaScript will run markedly slower than on V8 or similar production browser engines. It is also not intended to provide the full breadth of browser or Node.js APIs, only the core ECMAScript language, so any DOM-like or I/O functionality must be supplied by the embedding application itself. Teams needing high throughput or full web-platform compatibility should look elsewhere. Duktape's licensing and distribution model, as permissively licensed public-domain-style source rather than a package dependency, also makes it straightforward to vendor directly into a codebase and audit, which is a common requirement in firmware and safety-conscious embedded projects that cannot easily pull in external binary dependencies at build time.
Key Features
- Distributed as portable ANSI C source files rather than a prebuilt library
- Compiles JavaScript to a compact bytecode executed by a register-based VM
- Exposes a stack-based C API modeled on Lua's embedding style
- Optimized for small memory and binary footprint over raw execution speed
- Implements core ECMAScript without bundled DOM or Node.js-style APIs
- Runs on resource-constrained targets including microcontrollers
- Supports two-way calling between native C code and JavaScript functions