https://github.com/yinqiwen/so_script
https://github.com/yinqiwen/so_script
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/yinqiwen/so_script
- Owner: yinqiwen
- Created: 2018-03-28T03:10:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-14T02:29:01.000Z (over 7 years ago)
- Last Synced: 2025-01-05T10:43:11.181Z (10 months ago)
- Language: C++
- Size: 11.7 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
so_script
======A C++ library to run c/c++ source code on the fly like script.
## Limit
- Only works with LINUX/UNIX
- The running system must have GCC compiler.## Example
```cpp
void test_c()
{
using namespace so_script;
Script s;
s.AddInclude("./");
s.AddCompileFlag("-D__STDC_FORMAT_MACROS -pipe");
s.SetWorkDir("/tmp/so_script"); // the dir where so savedif (0 != s.Build("./test.c"))
{
printf("####%s\n", s.GetBuildError().c_str());
}
else
{
CEntryFunc entry = (CEntryFunc) s.GetFunc("hello_func");
entry(101);
}
}void test_cpp()
{
using namespace so_script;
Script s;
s.AddInclude("./");
s.AddCompileFlag("-D__STDC_FORMAT_MACROS -pipe");
s.SetWorkDir("/tmp/so_script"); // the dir where so savedif (0 != s.Build("./test2.cpp"))
{
printf("####%s\n", s.GetBuildError().c_str());
}
else
{
CppEntryFunc entry = (CppEntryFunc) s.GetFunc("hello_func");
std::string arg = "hello, world!";
entry(102, arg);
}
}
``````shell
cd test
g++ main.cpp ../so_script.cpp -I../ -ldl -rdynamic
./a.out```
## Embedding so_script
Just copy the source files without test into your project.