2017-05-06 106 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")