# 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())
|
| [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=48AGPL9FJX2D6) |
# License
```
Copyright (c) 2018 Northwestern Polytechnical University, Yong Zhao. All rights reserved.
This software was developed by the Yong Zhao at Northwestern Polytechnical University.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software must
display the following acknowledgement: This product includes software developed
by Northwestern Polytechnical University and its contributors.
4. Neither the name of the University nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```