Heather Andersonadded custom type support5f2b2c95 years agoHistory
1082 lines · 44.0 KB · C++
RawDownload
QStringList ScriptEngineQtScript::uncaughtExceptionBacktrace() const {    return QScriptEngine::uncaughtExceptionBacktrace();} int ScriptEngineQtScript::uncaughtExceptionLineNumber() const {    return QScriptEngine::uncaughtExceptionLineNumber();} bool ScriptEngineQtScript::raiseException(const ScriptValuePointer& exception) {    ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(exception);    QScriptValue qException = unwrapped ? unwrapped->toQtValue() : QScriptEngine::newVariant(exception->toVariant());    return raiseException(qException);} ScriptValuePointer ScriptEngineQtScript::create(int type, const void* ptr) {    // first we'll try custom types registered with us    ScriptEngine::MarshalFunction marshalFunc = nullptr;    ScriptValuePointer prototype;    {        std::lock_guard<std::mutex> guard(_customTypeProtect);        TCustomTypeMap::const_iterator loc = _customTypes.find(type);        if (loc != _customTypes.end()) {            const CustomTypeInfo& typeInfo = loc->second;            marshalFunc = typeInfo.marshalFunc;            prototype = typeInfo.prototype;        }    }    if (marshalFunc) {        ScriptValuePointer result = marshalFunc(this, ptr);        if (result && prototype) {            result->setPrototype(prototype);        }        return result;    }     // falling back to having QtScript handle it    QScriptValue result = qScriptValueFromValue_helper(this, type, ptr);    return ScriptValuePointer(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(result)));} bool ScriptEngineQtScript::convert(const ScriptValuePointer& value, int type, void* ptr) {    // first we'll try custom types registered with us    ScriptEngine::DemarshalFunction demarshalFunc = nullptr;    {        std::lock_guard<std::mutex> guard(_customTypeProtect);        TCustomTypeMap::const_iterator loc = _customTypes.find(type);        if (loc != _customTypes.end()) {            demarshalFunc = loc->second.demarshalFunc;        }    }    if (demarshalFunc) {        demarshalFunc(value, ptr);        return true;    }     // falling back to having QtScript handle it    ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(value);    if (unwrapped == nullptr) {        return false;    }    return qscriptvalue_cast_helper(unwrapped->toQtValue(), type, ptr);} void ScriptEngineQtScript::registerCustomType(int type,                                              ScriptEngine::MarshalFunction marshalFunc,                                              ScriptEngine::DemarshalFunction demarshalFunc,                                              const ScriptValuePointer& prototype){    ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(prototype);    if (unwrapped == nullptr) {        return;    }     std::lock_guard<std::mutex> guard(_customTypeProtect);    TCustomTypeMap::iterator loc = _customTypes.find(type);    if(loc == _customTypes.end()) {        _customTypes.insert(TCustomTypeMap::value_type(type, CustomTypeInfo())).first;    }    CustomTypeInfo& typeInfo = loc->second;    typeInfo.marshalFunc = marshalFunc;    typeInfo.demarshalFunc = demarshalFunc;}

Lines 1001–1082 of 1082. Previous lines

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t