Showing the changes to libraries/script-engine/src/qtscript/ScriptEngineQtScript.cpp (1 of 2 files). Show all
Unified · Split
| @@ -1013,25 +1013,70 @@ bool ScriptEngineQtScript::raiseException(const ScriptValuePointer& exception) { · 1012 unmodified lines | ||
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | ScriptValuePointer ScriptEngineQtScript::create(int type, const void* ptr) { |
| 1016 | + // first we'll try custom types registered with us | |
| 1017 | + ScriptEngine::MarshalFunction marshalFunc = nullptr; | |
| 1018 | + ScriptValuePointer prototype; | |
| 1019 | + { | |
| 1020 | + std::lock_guard<std::mutex> guard(_customTypeProtect); | |
| 1021 | + TCustomTypeMap::const_iterator loc = _customTypes.find(type); | |
| 1022 | + if (loc != _customTypes.end()) { | |
| 1023 | + const CustomTypeInfo& typeInfo = loc->second; | |
| 1024 | + marshalFunc = typeInfo.marshalFunc; | |
| 1025 | + prototype = typeInfo.prototype; | |
| 1026 | + } | |
| 1027 | + } | |
| 1028 | + if (marshalFunc) { | |
| 1029 | + ScriptValuePointer result = marshalFunc(this, ptr); | |
| 1030 | + if (result && prototype) { | |
| 1031 | + result->setPrototype(prototype); | |
| 1032 | + } | |
| 1033 | + return result; | |
| 1034 | + } | |
| 1035 | + | |
| 1036 | + // falling back to having QtScript handle it | |
| 1016 | 1037 | QScriptValue result = qScriptValueFromValue_helper(this, type, ptr); |
| 1017 | 1038 | return ScriptValuePointer(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(result))); |
| 1018 | 1039 | } |
| 1019 | 1040 | |
| 1020 | 1041 | bool ScriptEngineQtScript::convert(const ScriptValuePointer& value, int type, void* ptr) { |
| 1042 | + // first we'll try custom types registered with us | |
| 1043 | + ScriptEngine::DemarshalFunction demarshalFunc = nullptr; | |
| 1044 | + { | |
| 1045 | + std::lock_guard<std::mutex> guard(_customTypeProtect); | |
| 1046 | + TCustomTypeMap::const_iterator loc = _customTypes.find(type); | |
| 1047 | + if (loc != _customTypes.end()) { | |
| 1048 | + demarshalFunc = loc->second.demarshalFunc; | |
| 1049 | + } | |
| 1050 | + } | |
| 1051 | + if (demarshalFunc) { | |
| 1052 | + demarshalFunc(value, ptr); | |
| 1053 | + return true; | |
| 1054 | + } | |
| 1055 | + | |
| 1056 | + // falling back to having QtScript handle it | |
| 1021 | 1057 | ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(value); |
| 1022 | 1058 | if (unwrapped == nullptr) { |
| 1023 | 1059 | return false; |
| 1024 | 1060 | } |
| 1025 | 1061 | return qscriptvalue_cast_helper(unwrapped->toQtValue(), type, ptr); |
| 1026 | 1062 | } |
| 1027 | −/* | |
| 1063 | + | |
| 1028 | 1064 | void ScriptEngineQtScript::registerCustomType(int type, |
| 1029 | − ScriptEngine::MarshalFunction mf, | |
| 1030 | − ScriptEngine::DemarshalFunction df, | |
| 1031 | − const ScriptValuePointer& prototype) { | |
| 1065 | + ScriptEngine::MarshalFunction marshalFunc, | |
| 1066 | + ScriptEngine::DemarshalFunction demarshalFunc, | |
| 1067 | + const ScriptValuePointer& prototype) | |
| 1068 | +{ | |
| 1032 | 1069 | ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(prototype); |
| 1033 | − if (unwrapped != nullptr) { | |
| 1034 | − qScriptRegisterMetaType_helper(this, type, mf, df, unwrapped->toQtValue()); | |
| 1070 | + if (unwrapped == nullptr) { | |
| 1071 | + return; | |
| 1072 | + } | |
| 1073 | + | |
| 1074 | + std::lock_guard<std::mutex> guard(_customTypeProtect); | |
| 1075 | + TCustomTypeMap::iterator loc = _customTypes.find(type); | |
| 1076 | + if(loc == _customTypes.end()) { | |
| 1077 | + _customTypes.insert(TCustomTypeMap::value_type(type, CustomTypeInfo())).first; | |
| 1035 | 1078 | } |
| 1079 | + CustomTypeInfo& typeInfo = loc->second; | |
| 1080 | + typeInfo.marshalFunc = marshalFunc; | |
| 1081 | + typeInfo.demarshalFunc = demarshalFunc; | |
| 1036 | 1082 | } |
| 1037 | −*/ | |