I am developing a simple logic-gate simulation. For each logic gate type the following class is implemented:
class Gate {
public:
explicit Gate();
virtual ~Gate() = default;
virtual void update() = 0;
};
That means each gate type for example an AND gate can implement the Gate class and implement the logic for this gate inside the update method. These gate objects are then connected by pins and form a graph. When updates in a gate occur, all child gates are updated recursively. So far so good.
My goal now is to create a simple plugin system using shared libraries, which allows others to write own gates for this simple simulation. I now have issues regarding ABI compatibility. To solve all ABI issues I decided to use only C89 as the interface between plugin and main application. However, how should this work with my gate implementation? My plugin would have to implement the Gate class and implement the update method, which is okay, as the virtual Gate class is inside a header file both the plugin and the main application have access to. But I cannot share instances of the custom Gate implementation from the plugin with the main application, as it is a C++ object and it would break the ABI.
In the end it is a general issue. What if I want plugins to be able to implement classes to define custom behavior while keeping the interface between plugin and main application ABI compatible
How should I approach this?