I am working on a game that I want to have very good mod support. The game is programmed in C++ and will be completely open source. I would like to be able to have users add and remove mods easily. The game will be open source so modders will know how the code looks, but I would like for modders to be able to override functions in the compiled version of the code and to be able to add new functions. I would not like to create an explicit API or use another language for mods as those are necessarily restrictive on what can be done with them. The ideal situation is for the user to download a mod and put it in a mod folder, run the game once to load the mods, and then close it and run it again to load the game with the mods included. How could this be done?
An example would be, that if I had the program:
#include <iostream>
char const* getName();
int main() {
std::cout << getName() << std::endl;
}
char const* getName()
{
return "Robert";
}
I would be able to write a mod that has
char const* getName()
{
return "Steve";
}
in the same namespace, so that the result of the original code would be "Steve".