Recently I had to write some scripts to automatize some of my daily tasks. So I had to think about which scripting language to use. You’re probably not surprised when I say I went for C++. After trying several hacky approaches, I decided to try out Cling - a Clang-based C++ interpreter created by CERN.
Cling allows developers to write scripts using C and C++. Since it uses the Clang compiler, it supports the latest versions of the C++ standard. If you execute the interpreter directly, you'll have a live environment where you can start writing C++ code. As a part of the standard C/C++ syntax, you will find some other commands beginning with '.' (dot).
When you use the interactive interpreter, you can write code like:
As you can see, there is no need to worry about scopes; you can just call a function.
If you plan to use Cling as an interpreter for creating your scripts, you need to wrap everything inside of a function. The entry point of the script by default is the same as the file name. It can be customized to call another function. So, the previous example would turn into something like: