Just wanted to throw in my 2c for my particular use case which I think is similar:
I am using chaiscript (which I absolutely love by the way) in a mobile game.
Scripting is used for defining levels in the game - so the script calls C++ functions to create landscape, sprites etc. for each level.
I currently have a 'World' script that is using "use" to include scripts for the levels
use("w" + to_string(worldNo) + level + ".chai");
where worldNo is the world number and level is the level name - so the scripts are something like
As it stands, I can't have the same function name in the various level scripts, so I have to name the functions specific to the layer, e.g. L1LoadTerrain() rather than just loadTerrain().
When the player moves from level to level, the 'use' function loads the appropriate level script and all is well - but what would be great would be if it could first 'UnUse' the previous script.
That way the functions in each level script could be named identically, and the World script becomes very generic - simply calling the loadTerrain() method which will execute the function on the appropriate level.
Further to this, the ability to 'UnUse' a script would give the ability of downloading a new or modified script at runtime, which otherwise isn't possible (unless there is another way?)
The only alternative I've managed to use at present is to re-instantiate my chaiscript objects in C++ so if anyone knows of an alternative method ...