derofim / cling-cmake Goto Github PK
View Code? Open in Web Editor NEWuse cling scripting with C++ and cmake
License: MIT License
use cling scripting with C++ and cmake
License: MIT License
# NOTE: use -DLLVM_BUILD_TOOLS=Off, see https://github.com/root-project/cling/issues/297
cmake -DCMAKE_CXX_STANDARD=17 -DLLVM_BUILD_TOOLS=Off -DCMAKE_INSTALL_PREFIX=../release -DCMAKE_BUILD_TYPE=Release ../src
enable c++17 in cling
cling_args_storage.push_back("--std=c++17");
https://github.com/root-project/cling/tree/master/tools/demo
This example project uses cling as an external library. It compiles code and calls it, moving values from the compiled part to the interpreted part and back.
It showcases how to use cling as a library, and shows how to set up a simple CMake configuration that uses cling.
use relative paths to scripts
Any tutorials or samples you could share?
Best example is official demo: https://github.com/root-project/cling/blob/ee374738072fab73d2b9896c968a000cf0a1bfb4/tools/demo/cling-demo.cpp
Note that in cling-demo.cpp we can use global data and functions freely, as usual (see int aGlobal).
I use install_cling.sh from https://github.com/blockspacer/CXXCTP#how-to-build
Just copy install_cling.sh and FindCling.cmake into your project and link with cling::Interpreter library. CXXCTP is MIT licensed.
Than you can create cling::Interpreter
interpreter_ = std::make_uniquecling::Interpreter( interp_args.size(), &(interp_args[0]), LLVMDIR/, {}, false/);
See https://github.com/blockspacer/CXXCTP/blob/master/src/ClingInterpreterModule.cpp#L165
Than you can run any C++ code:
metaProcessor_->process(".L " + CPP_FILENAME_OR_ANY_CODE_HERE, compilationResult, nullptr, true);
If you want to pass not global data into script - wrap data into struct and convert pointer to that struct into hex string. See std::hex << std::showbase from https://github.com/blockspacer/CXXCTP/blob/master/src/clangPipeline.cpp#L220
Now you can get result of running code in Cling via cling::Value result;
I prefer to pass arbitrary data into cling::Value as void*, like so https://github.com/blockspacer/CXXCTP/blob/master/src/clangPipeline.cpp#L438
A lot of useful links can be found at README.md from https://github.com/derofim/cling-cmake
https://github.com/root-project/cling/tree/master/www/docs/talks https://github.com/caiorss/C-Cpp-Notes/blob/master/Root-cern-repl.org
Use Cling as C++ interpreter. No need to bind variables, just use them as usual.
Pro tip: you can not only use Cling as LUA replacement, but remove Cling in release build (for max. speed).
Cling can also be used for hot-code reload in whole project, no need to recompile anymore!
cd scripts before setup.sh
If you want to use cling, maybe following will be useful:
https://github.com/blockspacer/CXXCTP/blob/master/src/template_engine/engine_main.cpp#L20
Note argRefToCling
function, it allows to pass C++ variables into Cling (or maybe it is possible to do it easier).
// Or use macro / codegen
#define ARG_REF_TO_CLING(varType, varName) argRefToCling(varType, #varName, (varName))
Also note that usage example is reflection/codegen engine ( https://github.com/blockspacer/CXXCTP ), may be useful for game engine/level editor/e.t.c.
That project links to boost, add some static libs or:
Seems like cling does not support static libs, so we must use SHARED libs
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.