我目前正在使用ChaiScript版本6.0.0和Visual Studio 2017。
在我的C ++中,我正在从脚本文件中检索对函数on_init()
的引用,并执行它。 ChaiScript对象是使用默认/空构造函数构造的。该函数如下所示:
def on_init() {
use("scripts/test.chai");
}
" scripts / test.chai"的内容看起来像这样:
class A {
def A() {
print("Created an instance of A!");
}
}
我的文件结构如下:
bin
\
| my_executable.exe
| scripts
\
| main_menu.chai
| test.chai
执行上面显示的on_init()
函数时,控制台会输出以下消息:
Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use" Error: "Can not find object: use"
提供" usepaths"在构造ChaiScript对象时导致相同的情况。
我已尝试use("test.chai")
以及use("scripts/test.chai")
,两者都会产生相同的消息。
我没有在构建ChaiScript对象时提供任何chaiscript::Options
枚举,因此它应该使用默认值(它似乎包含External_Scripts
以及Load_Modules
)。
我正在编译ChaiScript,禁用线程安全。
我在运行此脚本的任何其他内置函数时没有任何问题,包括我正在检索的其他函数(进入C ++),方法与此相同。
如果还有其他信息,请与我们联系。
我使用"使用"功能不正确?
答案 0 :(得分:2)
编辑:当我写下这些内容时,一定非常高,但我会把它留在那里只是因为我很惊讶我甚至可以想出来。
真正的答案是您必须明确地将chaiscript::Options::External_Scripts
传递给ChaiScript
构造函数才能启用文件加载功能。
我是这样做的:
class ChaiPlugin
{
public:
/* stuff */
private:
chaiscript::ChaiScript chai = { {}, {}, { chaiscript::Options::External_Scripts } };
};
use
仅用于进行调试。
来自unittests/boxed_cast_test.cpp
:
template<typename T>
void use(T){}
我相信你要找的是usefile("scripts/test.chai")
。