} void ScriptEngineQtScript::setProcessEventsInterval(int interval) { QScriptEngine::setProcessEventsInterval(interval);} QThread* ScriptEngineQtScript::thread() const { return QScriptEngine::thread();} void ScriptEngineQtScript::setThread(QThread* thread) { moveToThread(thread);} ScriptValue ScriptEngineQtScript::uncaughtException() const { QScriptValue result = QScriptEngine::uncaughtException(); return ScriptValue(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(result)));} QStringList ScriptEngineQtScript::uncaughtExceptionBacktrace() const { return QScriptEngine::uncaughtExceptionBacktrace();} int ScriptEngineQtScript::uncaughtExceptionLineNumber() const { return QScriptEngine::uncaughtExceptionLineNumber();} bool ScriptEngineQtScript::raiseException(const ScriptValue& exception) { ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(exception); QScriptValue qException = unwrapped ? unwrapped->toQtValue() : QScriptEngine::newVariant(exception.toVariant()); return raiseException(qException);} ScriptValue ScriptEngineQtScript::create(int type, const void* ptr) { QScriptValue result = qScriptValueFromValue_helper(this, type, ptr); return ScriptValue(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(result)));} bool ScriptEngineQtScript::convert(const ScriptValue& value, int type, void* ptr) { ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(value); if (unwrapped == nullptr) { return false; } return qscriptvalue_cast_helper(unwrapped->toQtValue(), type, ptr);} template <int i>class CustomTypeInstance {public: static ScriptEngine::MarshalFunction marshalFunc; static ScriptEngine::DemarshalFunction demarshalFunc; static QScriptValue internalMarshalFunc(QScriptEngine* engine, const void* src) { ScriptEngineQtScript* unwrappedEngine = static_cast<ScriptEngineQtScript*>(engine); ScriptValue dest = marshalFunc(unwrappedEngine, src); return ScriptValueQtWrapper::fullUnwrap(unwrappedEngine, dest); } static void internalDemarshalFunc(const QScriptValue& src, void* dest) { ScriptEngineQtScript* unwrappedEngine = static_cast<ScriptEngineQtScript*>(src.engine()); ScriptValue wrappedSrc(new ScriptValueQtWrapper(unwrappedEngine, src)); demarshalFunc(wrappedSrc, dest); }};template <int i>ScriptEngine::MarshalFunction CustomTypeInstance<i>::marshalFunc;template <int i>ScriptEngine::DemarshalFunction CustomTypeInstance<i>::demarshalFunc; // I would *LOVE* it if there was a different way to do this, jeez!// Qt requires two functions that have no parameters that give any context,// one of the must return a QScriptValue (so we can't void* them into generics and stick them in the templates).// This *has* to be done via templates but the whole point of this is to avoid leaking types into the rest of// the system that would require anyone other than us to have a dependency on QtScript#define CUSTOM_TYPE_ENTRY(idx) \ case idx: \ CustomTypeInstance<idx>::marshalFunc = marshalFunc; \ CustomTypeInstance<idx>::demarshalFunc = demarshalFunc; \ internalMarshalFunc = CustomTypeInstance<idx>::internalMarshalFunc; \ internalDemarshalFunc = CustomTypeInstance<idx>::internalDemarshalFunc; \ break;#define CUSTOM_TYPE_ENTRY_10(idx) \ CUSTOM_TYPE_ENTRY((idx * 10)); \ CUSTOM_TYPE_ENTRY((idx * 10) + 1); \ CUSTOM_TYPE_ENTRY((idx * 10) + 2); \ CUSTOM_TYPE_ENTRY((idx * 10) + 3); \ CUSTOM_TYPE_ENTRY((idx * 10) + 4); \ CUSTOM_TYPE_ENTRY((idx * 10) + 5); \ CUSTOM_TYPE_ENTRY((idx * 10) + 6); \ CUSTOM_TYPE_ENTRY((idx * 10) + 7); \ CUSTOM_TYPE_ENTRY((idx * 10) + 8); \ CUSTOM_TYPE_ENTRY((idx * 10) + 9); void ScriptEngineQtScript::registerCustomType(int type, ScriptEngine::MarshalFunction marshalFunc, ScriptEngine::DemarshalFunction demarshalFunc, const ScriptValue& prototype){ QScriptValue unwrapped = ScriptValueQtWrapper::fullUnwrap(this, prototype); QScriptEngine::MarshalFunction internalMarshalFunc; QScriptEngine::DemarshalFunction internalDemarshalFunc; if (_nextCustomType >= 300) { // have we ran out of translators? Q_ASSERT(false); return; } switch (_nextCustomType++) { CUSTOM_TYPE_ENTRY_10(0); CUSTOM_TYPE_ENTRY_10(1); CUSTOM_TYPE_ENTRY_10(2); CUSTOM_TYPE_ENTRY_10(3); CUSTOM_TYPE_ENTRY_10(4); CUSTOM_TYPE_ENTRY_10(5); CUSTOM_TYPE_ENTRY_10(6); CUSTOM_TYPE_ENTRY_10(7); CUSTOM_TYPE_ENTRY_10(8); CUSTOM_TYPE_ENTRY_10(9); CUSTOM_TYPE_ENTRY_10(10); CUSTOM_TYPE_ENTRY_10(11); CUSTOM_TYPE_ENTRY_10(12); CUSTOM_TYPE_ENTRY_10(13); CUSTOM_TYPE_ENTRY_10(14); CUSTOM_TYPE_ENTRY_10(15); CUSTOM_TYPE_ENTRY_10(16); CUSTOM_TYPE_ENTRY_10(17); CUSTOM_TYPE_ENTRY_10(18); CUSTOM_TYPE_ENTRY_10(19); CUSTOM_TYPE_ENTRY_10(20); CUSTOM_TYPE_ENTRY_10(21); CUSTOM_TYPE_ENTRY_10(22); CUSTOM_TYPE_ENTRY_10(23); CUSTOM_TYPE_ENTRY_10(24); CUSTOM_TYPE_ENTRY_10(25); CUSTOM_TYPE_ENTRY_10(26); CUSTOM_TYPE_ENTRY_10(27); CUSTOM_TYPE_ENTRY_10(28); CUSTOM_TYPE_ENTRY_10(29); CUSTOM_TYPE_ENTRY_10(30); } qScriptRegisterMetaType_helper(this, type, internalMarshalFunc, internalDemarshalFunc, unwrapped);}Lines 1001–1143 of 1143. Previous lines
} void ScriptEngineQtScript::setProcessEventsInterval(int interval) { QScriptEngine::setProcessEventsInterval(interval); } QThread* ScriptEngineQtScript::thread() const { return QScriptEngine::thread(); } void ScriptEngineQtScript::setThread(QThread* thread) { moveToThread(thread); } ScriptValue ScriptEngineQtScript::uncaughtException() const { QScriptValue result = QScriptEngine::uncaughtException(); return ScriptValue(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(result))); } QStringList ScriptEngineQtScript::uncaughtExceptionBacktrace() const { return QScriptEngine::uncaughtExceptionBacktrace(); } int ScriptEngineQtScript::uncaughtExceptionLineNumber() const { return QScriptEngine::uncaughtExceptionLineNumber(); } bool ScriptEngineQtScript::raiseException(const ScriptValue& exception) { ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(exception); QScriptValue qException = unwrapped ? unwrapped->toQtValue() : QScriptEngine::newVariant(exception.toVariant()); return raiseException(qException); } ScriptValue ScriptEngineQtScript::create(int type, const void* ptr) { QScriptValue result = qScriptValueFromValue_helper(this, type, ptr); return ScriptValue(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(result))); } bool ScriptEngineQtScript::convert(const ScriptValue& value, int type, void* ptr) { ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(value); if (unwrapped == nullptr) { return false; } return qscriptvalue_cast_helper(unwrapped->toQtValue(), type, ptr); } template <int i> class CustomTypeInstance { public: static ScriptEngine::MarshalFunction marshalFunc; static ScriptEngine::DemarshalFunction demarshalFunc; static QScriptValue internalMarshalFunc(QScriptEngine* engine, const void* src) { ScriptEngineQtScript* unwrappedEngine = static_cast<ScriptEngineQtScript*>(engine); ScriptValue dest = marshalFunc(unwrappedEngine, src); return ScriptValueQtWrapper::fullUnwrap(unwrappedEngine, dest); } static void internalDemarshalFunc(const QScriptValue& src, void* dest) { ScriptEngineQtScript* unwrappedEngine = static_cast<ScriptEngineQtScript*>(src.engine()); ScriptValue wrappedSrc(new ScriptValueQtWrapper(unwrappedEngine, src)); demarshalFunc(wrappedSrc, dest); } }; template <int i> ScriptEngine::MarshalFunction CustomTypeInstance<i>::marshalFunc; template <int i> ScriptEngine::DemarshalFunction CustomTypeInstance<i>::demarshalFunc; // I would *LOVE* it if there was a different way to do this, jeez! // Qt requires two functions that have no parameters that give any context, // one of the must return a QScriptValue (so we can't void* them into generics and stick them in the templates). // This *has* to be done via templates but the whole point of this is to avoid leaking types into the rest of // the system that would require anyone other than us to have a dependency on QtScript #define CUSTOM_TYPE_ENTRY(idx) \ case idx: \ CustomTypeInstance<idx>::marshalFunc = marshalFunc; \ CustomTypeInstance<idx>::demarshalFunc = demarshalFunc; \ internalMarshalFunc = CustomTypeInstance<idx>::internalMarshalFunc; \ internalDemarshalFunc = CustomTypeInstance<idx>::internalDemarshalFunc; \ break; #define CUSTOM_TYPE_ENTRY_10(idx) \ CUSTOM_TYPE_ENTRY((idx * 10)); \ CUSTOM_TYPE_ENTRY((idx * 10) + 1); \ CUSTOM_TYPE_ENTRY((idx * 10) + 2); \ CUSTOM_TYPE_ENTRY((idx * 10) + 3); \ CUSTOM_TYPE_ENTRY((idx * 10) + 4); \ CUSTOM_TYPE_ENTRY((idx * 10) + 5); \ CUSTOM_TYPE_ENTRY((idx * 10) + 6); \ CUSTOM_TYPE_ENTRY((idx * 10) + 7); \ CUSTOM_TYPE_ENTRY((idx * 10) + 8); \ CUSTOM_TYPE_ENTRY((idx * 10) + 9); void ScriptEngineQtScript::registerCustomType(int type, ScriptEngine::MarshalFunction marshalFunc, ScriptEngine::DemarshalFunction demarshalFunc, const ScriptValue& prototype) { QScriptValue unwrapped = ScriptValueQtWrapper::fullUnwrap(this, prototype); QScriptEngine::MarshalFunction internalMarshalFunc; QScriptEngine::DemarshalFunction internalDemarshalFunc; if (_nextCustomType >= 300) { // have we ran out of translators? Q_ASSERT(false); return; } switch (_nextCustomType++) { CUSTOM_TYPE_ENTRY_10(0); CUSTOM_TYPE_ENTRY_10(1); CUSTOM_TYPE_ENTRY_10(2); CUSTOM_TYPE_ENTRY_10(3); CUSTOM_TYPE_ENTRY_10(4); CUSTOM_TYPE_ENTRY_10(5); CUSTOM_TYPE_ENTRY_10(6); CUSTOM_TYPE_ENTRY_10(7); CUSTOM_TYPE_ENTRY_10(8); CUSTOM_TYPE_ENTRY_10(9); CUSTOM_TYPE_ENTRY_10(10); CUSTOM_TYPE_ENTRY_10(11); CUSTOM_TYPE_ENTRY_10(12); CUSTOM_TYPE_ENTRY_10(13); CUSTOM_TYPE_ENTRY_10(14); CUSTOM_TYPE_ENTRY_10(15); CUSTOM_TYPE_ENTRY_10(16); CUSTOM_TYPE_ENTRY_10(17); CUSTOM_TYPE_ENTRY_10(18); CUSTOM_TYPE_ENTRY_10(19); CUSTOM_TYPE_ENTRY_10(20); CUSTOM_TYPE_ENTRY_10(21); CUSTOM_TYPE_ENTRY_10(22); CUSTOM_TYPE_ENTRY_10(23); CUSTOM_TYPE_ENTRY_10(24); CUSTOM_TYPE_ENTRY_10(25); CUSTOM_TYPE_ENTRY_10(26); CUSTOM_TYPE_ENTRY_10(27); CUSTOM_TYPE_ENTRY_10(28); CUSTOM_TYPE_ENTRY_10(29); CUSTOM_TYPE_ENTRY_10(30); } qScriptRegisterMetaType_helper(this, type, internalMarshalFunc, internalDemarshalFunc, unwrapped); }