Svar: A Tiny C++ Header Brings Unified Interface for Multiple programming Languages

Yong Zhao, Pengcheng Zhao, Shibiao Xu, Lin Chen, Pengcheng Han +2 more
8/19/2021
cs.PL

Official code: zdzhaoyong/Svar (157 stars, C++, last commit 2023-01-12).

Abstract

There are numerous types of programming languages developed in the last decades, and most of them provide interface to call C++ or C for high efficiency implementation. The motivation of Svar is to design an efficient, light-weighted and general middle-ware for multiple languages, meanwhile, brings the dynamism features from script language to C++ in a straightforward way.

Show full abstract

Firstly, a Svar class with JSON like data structure is designed to hold everything exists in C++, including basic values, functions or user defined classes and objects. Secondly, arguments are auto cast to and from Svar efficiently with compile time pointers, references and shared\_ptr detection. Thirdly, classes and functions are binded with string names to support reflection, this means all functions and classes in a shared library can be exported to a Svar object, which also calls a Svar module. The Svar modules can be accessed by different languages and this paper demonstrates how to import and use a Svar module in Python and Node.js. Moreover, the Svar modules or even a python module can also be imported by C++ at runtime, which makes C++ easier to compile and use since headers are not required anymore. We compare the performance of Svar with two state-of-the-art binding tool for Python and Node.js, and the result demonstrates that Svar is efficient, elegant and general. The core of this project is one single tiny modern C++ header with less than 5000 lines code without extra dependency. To help developers using Svar, all the source codes related are public available on http://github.com/zdzhaoyong/Svar, including documentations and benchmarks.

View on arXivView PDF

Code Implementations(1)

zdzhaoyong/SvarOfficial100%

A Tiny Modern C++ Header Brings Unified Interface for Different Languages

15718C++, CMakeDec 28, 20183 years agoNOASSERTION

Similar Papers

Cite this paper

@article{zhao2021svar,
  title  = {Svar: A Tiny C++ Header Brings Unified Interface for Multiple programming Languages},
  author = {Yong Zhao and Pengcheng Zhao and Shibiao Xu and Lin Chen and Pengcheng Han and Shuhui Bu and Hongkai Jiang},
  year   = {2021},
  eprint = {2108.08464},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2108.08464}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2108.08464.svg)](https://codeofpaper.com/paper/2108.08464)

Discussion