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. 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++ more 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 github http://github.com/zdzhaoyong/Svar, including documentations and benchmarks.
[1]
Yong Zhao,et al.
GSLAM: A General SLAM Framework and Benchmark
,
2019,
2019 IEEE/CVF International Conference on Computer Vision (ICCV).
[2]
Morgan Quigley,et al.
ROS: an open-source Robot Operating System
,
2009,
ICRA 2009.
[3]
Alon Zakai.
Emscripten: an LLVM-to-JavaScript compiler
,
2011,
OOPSLA Companion.
[4]
David M. Beazley,et al.
SWIG: An Easy to Use Tool for Integrating Scripting Languages with C and C++
,
1996,
Tcl/Tk Workshop.
[6]
Dawn Xiaodong Song,et al.
Tree-to-tree Neural Networks for Program Translation
,
2018,
NeurIPS.
[7]
Mehdi Amini,et al.
Pythran: Enabling Static Optimization of Scientific Python Programs
,
2013,
SciPy.
[8]
Guillaume Lample,et al.
Unsupervised Translation of Programming Languages
,
2020,
NeurIPS.
[9]
Shigeru Chiba,et al.
A metaobject protocol for C++
,
1995,
OOPSLA.
[10]
Wei Lu,et al.
C++ reflection for high performance problem solving environments
,
2007,
SpringSim '07.
[11]
Robert Harper,et al.
Practical Foundations for Programming Languages
,
2012
.