Skip to content

Commit 3933e8d

Browse files
committed
fix: 修复 WING_API 调用带有自定义类型会失败的问题;
1 parent a799a20 commit 3933e8d

8 files changed

Lines changed: 805 additions & 778 deletions

File tree

TestPlugin/lang/TestPlugin_zh_CN.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,12 @@
306306
<location filename="../testplugin.cpp" line="246"/>
307307
<location filename="../testplugin.cpp" line="253"/>
308308
<location filename="../testplugin.cpp" line="260"/>
309-
<location filename="../testplugin.cpp" line="288"/>
310-
<location filename="../testplugin.cpp" line="296"/>
311-
<location filename="../testplugin.cpp" line="304"/>
312-
<location filename="../testplugin.cpp" line="312"/>
313-
<location filename="../testplugin.cpp" line="321"/>
314-
<location filename="../testplugin.cpp" line="328"/>
309+
<location filename="../testplugin.cpp" line="286"/>
310+
<location filename="../testplugin.cpp" line="294"/>
311+
<location filename="../testplugin.cpp" line="302"/>
312+
<location filename="../testplugin.cpp" line="310"/>
313+
<location filename="../testplugin.cpp" line="319"/>
314+
<location filename="../testplugin.cpp" line="326"/>
315315
<source>InvalidParamsCount</source>
316316
<translation>无效参数个数</translation>
317317
</message>
@@ -322,7 +322,7 @@
322322
<translation>非法参数</translation>
323323
</message>
324324
<message>
325-
<location filename="../testplugin.cpp" line="279"/>
325+
<location filename="../testplugin.cpp" line="277"/>
326326
<source>AllocArrayFailed</source>
327327
<translation>分配数组失败</translation>
328328
</message>

TestPlugin/testplugin.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,9 @@ WingHex::UNSAFE_RET TestPlugin::colorTable(const QList<void *> &params) {
261261
}
262262

263263
void *array = nullptr;
264-
QVector<void *> colors;
265-
for (auto &c : colorTable()) {
266-
colors.append(&c);
267-
}
264+
265+
auto ctbl = colorTable(); // note: you should hold the reference
266+
auto colors = WingHex::normalizePackedVector(ctbl);
268267

269268
auto invoked =
270269
invokeService(QStringLiteral("WingAngelAPI"), "vector2AsArray",
@@ -275,7 +274,6 @@ WingHex::UNSAFE_RET TestPlugin::colorTable(const QList<void *> &params) {
275274
}
276275
}
277276

278-
qDeleteAll(colors);
279277
return generateScriptCallError(-2, tr("AllocArrayFailed"));
280278
}
281279

WingPlugin

lang/zh_CN/winghex_zh_CN.ts

Lines changed: 381 additions & 381 deletions
Large diffs are not rendered by default.

lang/zh_TW/winghex_zh_TW.ts

Lines changed: 381 additions & 381 deletions
Large diffs are not rendered by default.

src/class/pluginsystem.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,17 @@ bool PluginSystem::invokeServiceImpl(const QObject *sender, const QString &puid,
600600
if (met.name() == method) {
601601
bool err = false;
602602
for (int i = 1; i < paramCount; ++i) {
603-
if (met.parameterTypeName(i).compare(metaTypes[i]->name)) {
604-
err = true;
605-
break;
603+
if (metaTypes[i]->typeId == QMetaType::UnknownType) {
604+
// user defined meta type
605+
if (met.parameterTypeName(i).compare(metaTypes[i]->name)) {
606+
err = true;
607+
break;
608+
}
609+
} else {
610+
if (metaTypes[i]->typeId != met.parameterType(i)) {
611+
err = true;
612+
break;
613+
}
606614
}
607615
}
608616
if (err) {

src/class/wingangelapi.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,14 @@ void *WingAngelAPI::list2AsArray(const WingHex::SenderInfo &sender,
20832083
return vector2AsArray(sender, type, content);
20842084
}
20852085

2086+
void WingAngelAPI::releaseAsArray(const WingHex::SenderInfo &sender,
2087+
void *array) {
2088+
Q_UNUSED(sender);
2089+
if (array) {
2090+
reinterpret_cast<CScriptArray *>(array)->Release();
2091+
}
2092+
}
2093+
20862094
void *WingAngelAPI::newAsDictionary(
20872095
const WingHex::SenderInfo &sender,
20882096
const QHash<QString, QPair<WingHex::MetaType, void *>> &content) {
@@ -2104,6 +2112,14 @@ void *WingAngelAPI::newAsDictionary(
21042112
return dic;
21052113
}
21062114

2115+
void WingAngelAPI::releaseAsDictionary(const WingHex::SenderInfo &sender,
2116+
void *dic) {
2117+
Q_UNUSED(sender);
2118+
if (dic) {
2119+
reinterpret_cast<CScriptDictionary *>(dic)->Release();
2120+
}
2121+
}
2122+
21072123
void WingAngelAPI::cleanUpHandles(const QVector<int> &handles) {
21082124
for (auto &h : _handles) {
21092125
if (!handles.contains(h)) {

src/class/wingangelapi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,14 @@ class WingAngelAPI : public WingHex::IWingPlugin {
176176
WingHex::MetaType type,
177177
const QList<void *> &content);
178178

179+
WING_SERVICE void releaseAsArray(const WingHex::SenderInfo &sender,
180+
void *array);
181+
179182
WING_SERVICE void *newAsDictionary(
180183
const WingHex::SenderInfo &sender,
181184
const QHash<QString, QPair<WingHex::MetaType, void *>> &content);
185+
WING_SERVICE void releaseAsDictionary(const WingHex::SenderInfo &sender,
186+
void *dic);
182187

183188
// =========================================================
184189

0 commit comments

Comments
 (0)