Table of Contents
Fetching ...

Fat API bindings of C++ objects into scripting languages

Russell K. Standish

TL;DR

The paper tackles exposing a C++ core to scripting environments by implementing a fat API via reflection with Classdesc, enabling nearly all public attributes and methods to be accessed from TypeScript, Python, and REST clients. The authors couple a REST service with a C++ reflection layer to expose endpoints for attributes and methods, and provide Node.js and TypeScript bindings, plus Python integration, using JSON5 encoding and a dynamic descriptor. They address performance and build-time challenges through variadic templates, explicit instantiation, arity reduction, and linker choices, and demonstrate cross-language usability. The work offers a generalizable approach to bind C++ objects across languages, balancing accessibility, performance, and maintainability.

Abstract

A fat API exposes nearly all of a C++ object's public attributes and methods to a consuming environment, such as a scripting language, or web client. This can be contrasted with a conventional, or thin API, where the API is defined up front, and the C++ object provides the implementation, most of which is private to the C++ layer. Obviously, reflection is required to expose C++ objects to a consuming layer like this -- this paper explores using the Classdesc system to implement reflection of C++ objects into a JavaScript/TypeScript environment via a RESTservice, and also via a Node.js API module.

Fat API bindings of C++ objects into scripting languages

TL;DR

The paper tackles exposing a C++ core to scripting environments by implementing a fat API via reflection with Classdesc, enabling nearly all public attributes and methods to be accessed from TypeScript, Python, and REST clients. The authors couple a REST service with a C++ reflection layer to expose endpoints for attributes and methods, and provide Node.js and TypeScript bindings, plus Python integration, using JSON5 encoding and a dynamic descriptor. They address performance and build-time challenges through variadic templates, explicit instantiation, arity reduction, and linker choices, and demonstrate cross-language usability. The work offers a generalizable approach to bind C++ objects across languages, balancing accessibility, performance, and maintainability.

Abstract

A fat API exposes nearly all of a C++ object's public attributes and methods to a consuming environment, such as a scripting language, or web client. This can be contrasted with a conventional, or thin API, where the API is defined up front, and the C++ object provides the implementation, most of which is private to the C++ layer. Obviously, reflection is required to expose C++ objects to a consuming layer like this -- this paper explores using the Classdesc system to implement reflection of C++ objects into a JavaScript/TypeScript environment via a RESTservice, and also via a Node.js API module.
Paper Structure (9 sections, 1 figure, 3 tables)

This paper contains 9 sections, 1 figure, 3 tables.

Figures (1)

  • Figure 1: Build times for the different build time optimisations for the two different compiler toolchains.