# Svar **Repository Path**: VisionDeveloper/Svar ## Basic Information - **Project Name**: Svar - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2022-07-02 - **Last Updated**: 2024-12-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Svar, A Tiny Modern C++ Header Brings Unified Interface for Different Languages --- [](https://travis-ci.org/zdzhaoyong/Svar) [](https://circleci.com/gh/zdzhaoyong/Svar) [](https://www.codacy.com/app/zdzhaoyong/Svar) [](./LICENSE) [](https://github.com/zdzhaoyong/Svar/releases) - [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 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) - [Supported Compilers](#supported-compilers) - [Contact and Donation](#contact-and-donation) - [License](#license) --- # 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()) |