我可以 parse/compile 一次 ChaiScript 脚本并多次调用它吗?

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

我正在尝试确定我是否可以使用 ChaiScript,但到目前为止我非常担心似乎没有办法编译脚本供以后使用。例如,如果脚本必须每秒调用数百次,这将是一个问题。

我找到的所有示例都引用了一个名为 eval 的 C++ 函数,该函数将整个脚本作为参数并 运行s 它。

那么是否可以将编译和运行步骤分开?

您的评论:

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?

这是最好的处理方式。 eval 将只解析一次代码。当您对结果使用 std::function 并调用它时,您将以最有效的方式调用脚本。