Reputation: 61
I want to implement scripting system with Entity Component System, as in Unity or Unreal Engine 4. I have written my engine in c++ and want to use c++ as a scripting language. Now i am looking for way to store script classes in some binary format, so i my engine load them, create instance and use needed methods. I know that dll can be used for this purpose, but there is several problems: you need to write fucntion call conventions, (dllimport) and etc. and you can't create instance of class directly, you need to write a function, which will create instance of class, in your script. So how to avoid this problems? I know it is possible to use macros for call conventions to make code cleaner,like UE4 does, but is it possible to create instance of class direcly in my engine without using special functions in dll? Or is there any other binary format for user scripts in which c++ can be compiled?
Upvotes: 4
Views: 1769
Reputation: 662
TL;DR:
Yes, there are some libraries help you make C++ as interpreter.
Long answer:
In theory, C++ is compile language, not interpreter language like Lua. But there are not impossible with some open source libraries, which "runtime linker that detects changes to source code files, compiles them and links them back into the running application, while patching all updated functions to jump to the new code".
For specific OS:
For cross-platform:
I recommend to use other languages as interpreter language.
I had some pains with some interpreter languages, too hard to integrate their interpreter or JIT (Just-In-Time) or AOT (Ahead-Of-Time) compiler into engine. May be Lua is better choice for game (easy to learn, faster build prototype than compiled language, faster for integrate to engine than other interpreter language).
For development, use official Lua library, a question in StackOverflow guide how to integrate this
In case, you care about performance of Lua, use lua-aot instead that.
Upvotes: 1
Reputation: 51
Since you want to use c++ as a scripting language, maybe you can refer to the C++ interpreter cling
in the ROOT
project: http://root.cern.ch/
cling
is an interpreter for C++, which could be helpful for your project.
Upvotes: 3