mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Merge pull request #890 from dumganhar/jsb2.0
Adds seval_to_Map_string_key convertion function.
This commit is contained in:
@@ -136,7 +136,7 @@ bool seval_to_Vector(const se::Value& v, cocos2d::Vector<T>* ret)
|
||||
for (uint32_t i = 0; i < len; ++i)
|
||||
{
|
||||
ok = obj->getArrayElement(i, &tmp);
|
||||
if (!ok && tmp.isObject())
|
||||
if (!ok || !tmp.isObject())
|
||||
{
|
||||
ret->clear();
|
||||
return false;
|
||||
@@ -150,6 +150,39 @@ bool seval_to_Vector(const se::Value& v, cocos2d::Vector<T>* ret)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool seval_to_Map_string_key(const se::Value& v, cocos2d::Map<std::string, T>* ret)
|
||||
{
|
||||
assert(ret != nullptr);
|
||||
assert(v.isObject());
|
||||
se::Object* obj = v.toObject();
|
||||
|
||||
std::vector<std::string> allKeys;
|
||||
bool ok = obj->getAllKeys(&allKeys);
|
||||
if (!ok)
|
||||
{
|
||||
ret->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
se::Value tmp;
|
||||
for (const auto& key : allKeys)
|
||||
{
|
||||
ok = obj->getProperty(key.c_str(), &tmp);
|
||||
if (!ok || !tmp.isObject())
|
||||
{
|
||||
ret->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
T nativeObj = (T)tmp.toObject()->getPrivateData();
|
||||
|
||||
ret->insert(key, nativeObj);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// native value -> se value
|
||||
bool int8_to_seval(int8_t v, se::Value* ret);
|
||||
bool uint8_to_seval(uint8_t v, se::Value* ret);
|
||||
|
||||
Reference in New Issue
Block a user