Search code examples
compilationevaluationchaiscript

Can I parse/compile a ChaiScript script once and invoke it many times?


I'm trying to determine whether I can use ChaiScript but so far I'm very concerned that there doesn't seem to be a way to compile a script to use later. This would be a problem if a script has to be called hundreds of times per second, for example.

All the examples I've found refer to a C++ function called eval which takes an entire script as an argument and runs it.

So is it possible to separate the compile and run steps?


Solution

  • Your comment:

    From experiments, it looks like I just use eval to request a reference to a function and then I can just invoke that function multiple times directly. Does that invoke the compiled code directly?

    This is the best way to handle it. The eval will parse the code exactly once. When you take a std::function to the result and call that, you will be calling into your script the most efficient way you can.