History

Fixes to most scripting-related warnings

ksuprynowicz committed 4 years ago

Commit 6f321731 parent a14c64435 files · +195 −149Browse files

Showing the changes to libraries/script-engine/src/ScriptEngineCast.h (1 of 35 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngineCast.h+34−8
@@ -66,8 +66,39 @@ inline QVariant scriptvalue_cast<QVariant>(const ScriptValue& value) { · 65 unmodified lines
66 return value.toVariant();66 return value.toVariant();
67}67}
68 68
69//#define MARSHAL_MACRO(FUNCTION, TYPE) +[FUNCTION](ScriptEngine* engine, const void* p) -> ScriptValue { FUNCTION(engine, *(static_cast<const TYPE*>(p)) ); }
70
71template <typename T, ScriptValue (*f)(ScriptEngine*, const T&)>
72ScriptValue toScriptValueWrapper(ScriptEngine* engine, const void *p) {
73 Q_ASSERT(p != NULL);
74 auto &src = *(reinterpret_cast<const T*>(p));
75 return f(engine, src);
76}
77
78template <typename T, bool (*f)(const ScriptValue&, T&)>
79bool fromScriptValueWrapper(const ScriptValue& val, void* p) {
80 Q_ASSERT(p != NULL);
81 auto &dest = *(reinterpret_cast<T*>(p));
82 return f(val, dest);
83}
84
85template <typename T, ScriptValue (*toScriptValue)(ScriptEngine*, const T&), bool (*fromScriptValue)(const ScriptValue&, T&)>
86int scriptRegisterMetaType(ScriptEngine* eng, const char* name = "",
87 T* = 0)
88{
89 int id;
90 if (strlen(name) > 0) { // make sure it's registered
91 id = qRegisterMetaType<T>(name);
92 } else {
93 id = qRegisterMetaType<T>();
94 }
95 eng->registerCustomType(id, toScriptValueWrapper<T, toScriptValue>,
96 fromScriptValueWrapper<T, fromScriptValue>);
97 return id;
98}
99
69template <typename T>100template <typename T>
70int scriptRegisterMetaType(ScriptEngine* eng,101int scriptRegisterMetaTypeWithLambdas(ScriptEngine* eng,
71 ScriptValue (*toScriptValue)(ScriptEngine*, const T& t),102 ScriptValue (*toScriptValue)(ScriptEngine*, const T& t),
72 bool (*fromScriptValue)(const ScriptValue&, T& t), const char* name = "",103 bool (*fromScriptValue)(const ScriptValue&, T& t), const char* name = "",
73 T* = 0)104 T* = 0)
@@ -76,12 +107,7 @@ int scriptRegisterMetaType(ScriptEngine* eng, · 2 unmodified lines
76 if (strlen(name) > 0) { // make sure it's registered107 if (strlen(name) > 0) { // make sure it's registered
77 id = qRegisterMetaType<T>(name);108 id = qRegisterMetaType<T>(name);
78 } else {109 } else {
79 //if (!QMetaType::fromType<T>().name().isNull()) {110 id = qRegisterMetaType<T>();
80 //qDebug() << "scriptRegisterMetaType: " << QMetaType::fromType<T>().name();
81 //id = qRegisterMetaType<T>(QMetaType::fromType<T>().name());
82 //}else{
83 id = qRegisterMetaType<T>();
84 //}
85 }111 }
86 eng->registerCustomType(id, reinterpret_cast<ScriptEngine::MarshalFunction>(toScriptValue),112 eng->registerCustomType(id, reinterpret_cast<ScriptEngine::MarshalFunction>(toScriptValue),
87 reinterpret_cast<ScriptEngine::DemarshalFunction>(fromScriptValue));113 reinterpret_cast<ScriptEngine::DemarshalFunction>(fromScriptValue));
@@ -148,7 +174,7 @@ bool scriptValueToEnumClass(const ScriptValue& value, T& enumValue) { · 60 unmodified lines
148template <typename T>174template <typename T>
149int scriptRegisterSequenceMetaType(ScriptEngine* engine,175int scriptRegisterSequenceMetaType(ScriptEngine* engine,
150 T* = 0) {176 T* = 0) {
151 return scriptRegisterMetaType<T>(engine, scriptValueFromSequence, scriptValueToSequence);177 return scriptRegisterMetaType<T, scriptValueFromSequence, scriptValueToSequence>(engine);
152}178}
153 179
154#endif // hifi_ScriptEngineCast_h180#endif // hifi_ScriptEngineCast_h