2017-05-06 102 views
0

我目前使用ChaiScript 6.0.0版和Visual Studio 2017错误:“找不到对象:使用”

在我的C++,我检索从脚本文件的功能on_init()参考,并执行它。 ChaiScript对象是使用默认/空构造函数构造的。功能如下:

def on_init() { 
    use("scripts/test.chai"); 
} 

的内容 “脚本/ 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" 

构建ChaiScript对象时提供“usepaths”会导致相同的情况。

我试过use("test.chai")以及use("scripts/test.chai"),并且两者都产生相同的消息。

我没有提供任何构造ChaiScript对象的chaiscript::Options枚举,所以它应该使用默认值(其中包含External_Scripts以及Load_Modules)。

我正在编译禁用线程安全的ChaiScript。

我没有任何问题在这个脚本的正文中运行其他任何内置函数,包括其他函数,我正以同样的方式检索(到C++)。

如果有任何需要的信息,请告诉我。

我是否正确使用“使用”功能?

+0

它表现得像可用性完全从可执行文件中丢失。那或者,'test.chai'是一些正在引发递归的事情。两个都很奇怪但我需要一个更完整的例子来诊断。 'use'用于* all *单元测试,所以它已知可以工作。 – lefticus

回答

1

编辑:当我写下下面的东西时,一定会非常高,但我会留在那里,因为我很惊讶,我甚至可以想出来。

真实答案是,您必须明确地将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")