I am learning C++ now and I have heard a lot about embedded scripting languages. I imagined it completely different.
I thought I would write all of my performance heavy functions in C++ and call them out of a scripting language such as Lua or Python.
But it seems it is the other way around. -> Write functions in Lua/Python and call them in C code.
What is the advantage of embedding a language in C++ instead of writing an API in C++ and calling those functions in another language?
Example:
// function in c++
int expensiveFunction(){
return 1;
}
Then in Python I would call this function and I would have the performance from C++ but can make changes at runtime thanks to Python's runtime interpreter.
Actually, a lot of game engines like to build interfaces to the engine by embedding Lua or Python. There are advantages to this:
C++ is quite useful as a backend for projects that want the flexability of scripting languages, but want the performance of C++. I have not heard of projects that use C++ as a frontend, with a scripting language as the backend.
API Style
We use this style in my company's software. We expose an API through a Windows DLL that can be called by most languages fairly easily. We specifically support VB and VBA. This is great when the backend is from outside the script maker's control. However, it is hard to debug issues that arise from the script maker's perspective.
Advantages
Disadvantages
Embedded Style
The software actually embeds the script interpreter into the software. This way you can expose features as if they were native functions. In this style, the script makers and the backend programmers typically are in the same company. It can also be used by traditional software to allow others to extend the functionality of the application. If they share source code, you can debug problems arising from scripts in a much easier manner. The application also takes care of when and how to launch your scripts. However, in order to support additional languages, the application developer has to embed other interpreters.
Advantages
Disadvantages
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With