# Svar **Repository Path**: pi-lab/Svar ## Basic Information - **Project Name**: Svar - **Description**: A Flexible C++ Variable Container - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 4 - **Created**: 2021-03-10 - **Last Updated**: 2025-09-30 ## Categories & Tags **Categories**: utils **Tags**: None ## README # Svar - A Flexible C++ Variable Container Svar is a powerful tiny modern c++ header implemented variable container and unified interface for different languages. To use the package, the best way is to use the example codes: * [samples](src/Svar_packages/sample/sample.cpp) * [sample module](src/modules/sample_module/module.cpp) ## 分支说明 * master: 主分支 * windowsBuild: 在Windows平台使用Python 3.12编译Svar-0.2.2时遇到的主要问题和解决方案。 ## Related projects: * [Svar-allinone](https://gitee.com/pi-lab/Svar-allinone) - Svar模块 * [GSLAM](https://gitee.com/pi-lab/GSLAM) - GSLAM,视觉计算库 * [PI-Mavlink](https://gitee.com/pi-lab/pi-mavlink) - Mavlink,无人机管理,集群 * [code_cook](https://gitee.com/pi-lab/code_cook) - 代码实例 ## Svar documentation index - [Why Svar](#why-svar) - [Compile and Install](#compile-and-install) - [Usages](#usages) - [Perform tests](#perform-tests) - [Use Svar like JSON](#use-svar-like-json) - [Use Svar for Argument Parsing](#use-svar-for-argument-parsing) - [Svar Holding Everything](#svar-holding-everything) - [Hold Various Variables](#hold-various-variables) - [Hold Class Instances](#hold-class-instances) - [Hold Functions](#hold-functions) - [Hold and Use a Class](#hold-and-use-a-class) - [Create and Use a Svar Module](#create-and-use-a-svar-module) - [Create a Svar Module](#create-a-svar-module) - [The Svar Module Documentation](#the-svar-module-documentation) - [Import and Use a Svar Module](#import-and-use-a-svar-module) - [Use Svar Module in Other Languages](#use-svar-module-in-other-languages) - [References](#references) ## Quick start
| 1. Bind C++ to hello.so | 2. Import by C++ | 3. Import by Python |
|---|---|---|
#include <Svar.h>
void say(std::string v){
std::cerr<<v<<std::endl;
}
REGISTER_SVAR_MODULE(hello)
{
svar["say"] = say;
}
EXPORT_SVAR_INSTANCE
|
#include <Svar.h>
auto m=svar.import("hello");
int main(){
m["say"]("hello world");
return 0;
}
|
import svar
hello = svar.load("hello")
hello.say("hello world")
|
| 4. Import by Javascript | 5. C++ import Python | 6. Javascript import Python |
svar = require('./svar')
hello = svar('hello')
hello.say("hello world")
|
#include <Svar.h>
auto py=svar.import("svarpy");
int main(){
auto os = py["import]("os");
std::cout<<"Pid is:"
<<os["getpid"]();
return 0;
}
|
svar=require("./svar")
python=svar("svarpy")
os=python.import("os")
print("Pid is", os.getpid())
|