First of all, thanks for the contributions you make to the C++ community. I discovered chaiscript by watching some of the Cppcon videos. I watched your presentation at this year’s cppcon which led me to the Chaiscript site. I have also watched a number of your weekly presentations on youtube, and read most of your best practices website at least a couple of times. All very helpful to me. Thanks for that.
I lead programming efforts on a commercial product that uses a built in scripting language. We built the ‘interpreter’ ourselves, based upon an old Dr. Dobbs Journal article. The code is working very well, but the language features on the script side are not conducive to maintainable scripts. It is more ‘basic’ like than C like. Since all of our source code is in C++, I have always wanted for a scripting engine that would allow for more C++ like code. Enter Chaiscript.
I am tinkering with Chaiscript as a migration path to deprecate our existing “Basic Script” functionality. I have been very pleased so far, but now I’m coming up with questions I can’t find answers to in the existing discussions.
I’ll start by how we use our existing scripting engine. Our end product does quality testing. We test a number of different types of components, and each type requires a different sequence of events. We orchestrate the sequence of events required to run a test with a specific script that we ‘execute’ with our scripting engine. Each time we execute a test, we tell our scripting engine to execute the appropriate script for the part being tested. Each time we start a script, the engine starts in a known initial state, and is though no script has been run. Beside there being different part types, there are many different ‘recipes’ of each part type. The contents of the recipe are loaded from a database into an object in our code. When a script runs, it has access to data held in that object which describes a specific part of the type that the script is designed to test.
I have gotten Chaiscript to a point where I can execute simple scripts, and exchange basic information. The specific issue I am running in to at this point is getting a chaiscript::ChaiScript object back to the initial state, so I can execute the same script again. This is somewhat simply overcome by re-creating the ChaiScript object. The problem is the creation process seems to be very expensive. It takes about 3 seconds to instantiate the Chaiscript object in my case. I’m not adding many of my functions yet, either. I don’t know if adding several hundred more things will make the creation process more expensive.
The path I chose was to create an object when my software starts up, and just keep it around for the life of the program. Then tell that object to execute a file whenever I start a test. That solved the problem of losing a few seconds while the Chaiscript object instantiated, but it cause the problem of not being able to run the same script over and over. Our existing scripting system goes back to carte-blanche state after completing an execution.
I have read what I can find on this issue, and I think I basically understand that this is not the way Chaiscript is designed to function. What I’m trying to do is figure out how if there is a different way to attack our problem, using Chaiscript the way it was designed.
( is it feasible to simply create a copy of the chai object after I do all of my adding, then copy that object before or after my execution? - or will the copy process take as long as the instantiation? )
For example, perhaps we should be executing a script that creates a state in the Chai object whereby we could trigger the execution of a test, instead of executing the script again. Maybe that would allow us to load all of our scripts into a chai object, then trigger which specific sequence we want to execute based upon part type. (We only have about 6 ‘types’ of parts, but potentially thousands of specific instance of the different part types). So if we could prepare the chai object by executing scripts that would create some operational state where we could prepare the specific data, then trigger a function or sequence within the chai object.
Perhaps our existing scripts are just organized wrong for how chai works. Our current scripts define variables and establish ‘state’, then execute a sequence of events based upon that state. Perhaps with chai we should execute a script that defines the state variables, then have script(s) that assign to the state variables (but don’t re-define them), and execute based upon the state variables.
I’m rambling at this point, but I don’t know how else to convey my struggle. I don’t think changes are needed to chaiscript as much as we need to figure out how to change our paradigm to fit how chaiscript operates.
If any of this makes sense, please attempt to give your thoughts on how you would apply chai to what we are trying to do.
And, keep up the good work.