2

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?

David
  • 5,991
  • 5
  • 33
  • 39
  • 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? – David Jun 07 '16 at 03:16

1 Answers1

3

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.

lefticus
  • 3,346
  • 2
  • 24
  • 28
  • Yeah, it works --- unfortunately, if there is a problem with the script, the exception handling mechanism, while catching an exception, provides zero useful information about the problem. – David Jun 09 '16 at 19:50
  • I stand corrected --- while fields like 'details' and 'filename' don't get filled in, pretty_print() does return useful info. Unfortunately, I'll have to pull the resulting string apart to get at the parts I need --- I don't want to just display that pretty_print error to the end user. – David Jun 09 '16 at 20:12
  • @David You actually have access to the entire call stack at the time of the error: https://github.com/ChaiScript/ChaiScript/blob/develop/include/chaiscript/language/chaiscript_common.hpp#L111 but this is now far off topic for this stackoverflow question. I suggest you move the discussion to http://discourse.chaiscript.com – lefticus Jun 09 '16 at 20:33
  • Thanks, I've created an account there and posted my other questions. – David Jun 09 '16 at 21:57