我確定必須有一個簡單的答案,但我找不到任何有關文檔或通過一些最初的Google搜索的參考。使用2D雙數組綁定類時出現Emscripten錯誤
基本上,我有一個類,它看起來是這樣的:
#define NX 65
#define NY 65
class myclass{
// other stuff
public:
//other stuff.. more functions and more variables
// a function I want to call every so often with a few different cases
void solve(int case);
// a 2D double array that I want to access in JS
double ux[NX+1][NY+1];
}
還有其它使用的函數和變量,但沒有人將被直接調用JavaScript中。
現在,我想我們embind,這樣我可以創造我的對象,做這樣的事情:
x = new Module.myclass();
x.solve(2); // parameter is irrelevant
for (i=0; i<x.ux.length; i++) {
for (j=0; j<x.ux[i].length; j++) {
// do something with the data
console.log(x.ux[i][j]);
}
}
因此,很自然,我做這樣的事情:
EMSCRIPTEN_BINDINGS(myclass) {
class_<myclass>("myclass")
.function("solve", &myclass::solve)
.property("ux", &LBM::getux, &LBM::setux)
;
}
這些都是我的getter和setter
void setux(double uxnew[NX+1][NY+1]) {
for (int i=0; i<NX+1; i++) {
for (int j=0; j<NY+1; j++) {
ux[i][j] = uxnew[i][j];
}
}
};
double getux() { return **ux; };
再就是這些錯誤:
In file included from ../../lbm.cpp:10:
/home/vagrant/src/emscripten/system/include/emscripten/bind.h:1043:33: error: implicit instantiation of undefined template 'emscripten::internal::GetterPolicy<double (LBM::*)()>'
TypeID<typename GP::ReturnType>::get(),
^
../../lbm.cpp:1264:18: note: in instantiation of function template specialization 'emscripten::class_<LBM, emscripten::internal::NoBaseClass>::property<double (LBM::*)(), void (LBM::*)(double (*)[66])>' requested here
.property("p", &LBM::getp, &LBM::setp)
^
/home/vagrant/src/emscripten/system/include/emscripten/bind.h:428:16: note: template is declared here
struct GetterPolicy;
那麼有誰知道如何處理emscripten中的雙數組?我真的希望我不會錯過文檔的一部分。如果我沒有,這真的需要包含在網頁上。
另外,我對任何不一致道歉。這不是一個複雜的問題(表面上)。我只是不知道該怎麼做。
我會在稍後測試。如果我在賞金到期之前沒有做到這一點,至少可以得到它看起來像完美的建議。 – Logan
謝謝,洛根。我想我已經讀過,如果它過期並超過寬限期,它需要兩個upvotes。但它根本沒有什麼大不了的,我只希望這能讓你獲得你需要的東西。我注意到有一些關於emscripten的創建者參與的數組的討論,但我認爲這是一個很好的指向JS對象,數組或原始函數的指針,用於處理內存訪問和C/C++方面可能適合我能想到的大多數需求。無論如何,我的意見都在代碼中,所以我希望它沒有問題。 – hoonto
好的,所以我的指針fu確實很弱。我的數組是'double p [NX + 1] [NY + 1]',我用同樣的getter作爲你的例子,'int's改爲'double's。然而,我仍然得到一個錯誤:'C型從'double(*)[66] [66]'轉換爲'double'是不允許的' – Logan