mirror of
https://github.com/overte-org/overte.git
synced 2025-07-28 23:20:30 +02:00
Fixes to scripting-related warnings (lambdas)
This commit is contained in:
parent
9fe83882e4
commit
adee1aeadf
2 changed files with 32 additions and 15 deletions
|
@ -328,13 +328,17 @@ namespace scriptable {
|
||||||
scriptRegisterSequenceMetaType<QVector<QPointer<T>>>(engine);
|
scriptRegisterSequenceMetaType<QVector<QPointer<T>>>(engine);
|
||||||
return scriptRegisterMetaTypeWithLambdas<QPointer<T>>(
|
return scriptRegisterMetaTypeWithLambdas<QPointer<T>>(
|
||||||
engine,
|
engine,
|
||||||
[](ScriptEngine* engine, const QPointer<T>& object) -> ScriptValue {
|
[](ScriptEngine* engine, const void* p) -> ScriptValue {
|
||||||
|
Q_ASSERT(p != NULL);
|
||||||
|
const QPointer<T>& object = *(reinterpret_cast<const QPointer<T>* >(p));
|
||||||
if (!object) {
|
if (!object) {
|
||||||
return engine->nullValue();
|
return engine->nullValue();
|
||||||
}
|
}
|
||||||
return engine->newQObject(object, ScriptEngine::QtOwnership, ScriptEngine::AutoCreateDynamicProperties);
|
return engine->newQObject(object, ScriptEngine::QtOwnership, ScriptEngine::AutoCreateDynamicProperties);
|
||||||
},
|
},
|
||||||
[](const ScriptValue& value, QPointer<T>& out) -> bool {
|
[](const ScriptValue& value, void* p) -> bool {
|
||||||
|
Q_ASSERT(p != NULL);
|
||||||
|
QPointer<T>& out = *(reinterpret_cast<QPointer<T>* >(p));
|
||||||
auto obj = value.toQObject();
|
auto obj = value.toQObject();
|
||||||
#ifdef SCRIPTABLE_MESH_DEBUG
|
#ifdef SCRIPTABLE_MESH_DEBUG
|
||||||
qCInfo(graphics_scripting) << "qpointer_qobject_cast" << obj << value.toString();
|
qCInfo(graphics_scripting) << "qpointer_qobject_cast" << obj << value.toString();
|
||||||
|
@ -670,24 +674,18 @@ namespace scriptable {
|
||||||
static const DebugEnums<T>& instance = debugEnums;
|
static const DebugEnums<T>& instance = debugEnums;
|
||||||
return scriptRegisterMetaTypeWithLambdas<T>(
|
return scriptRegisterMetaTypeWithLambdas<T>(
|
||||||
engine,
|
engine,
|
||||||
[](ScriptEngine* engine, const T& topology) -> ScriptValue {
|
[](ScriptEngine* engine, const void* p) -> ScriptValue {
|
||||||
|
Q_ASSERT(p != NULL);
|
||||||
|
const T& topology = *(reinterpret_cast<const T*>(p));
|
||||||
return engine->newValue(instance.value(topology));
|
return engine->newValue(instance.value(topology));
|
||||||
},
|
},
|
||||||
[](const ScriptValue& value, T& topology) -> bool {
|
[](const ScriptValue& value, void* p) -> bool {
|
||||||
|
Q_ASSERT(p != NULL);
|
||||||
|
T& topology = *(reinterpret_cast<T*>(p));
|
||||||
topology = instance.key(value.toString());
|
topology = instance.key(value.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
//return scriptRegisterMetaType<T>(
|
|
||||||
// engine,
|
|
||||||
// [](ScriptEngine* engine, const T& topology) -> ScriptValue {
|
|
||||||
// return engine->newValue(instance.value(topology));
|
|
||||||
// },
|
|
||||||
// [](const ScriptValue& value, T& topology) -> bool {
|
|
||||||
// topology = instance.key(value.toString());
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,25 @@ int scriptRegisterMetaType(ScriptEngine* eng, const char* name = "",
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This can be safely removed and replaced with scriptRegisterMetaType once we use C++20 everywhere
|
||||||
|
template <typename T>
|
||||||
|
int scriptRegisterMetaTypeWithLambdas(ScriptEngine* eng,
|
||||||
|
ScriptValue (*toScriptValue)(ScriptEngine*, const void *),
|
||||||
|
bool (*fromScriptValue)(const ScriptValue&, void *), const char* name = "",
|
||||||
|
T* = 0)
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
if (strlen(name) > 0) { // make sure it's registered
|
||||||
|
id = qRegisterMetaType<T>(name);
|
||||||
|
} else {
|
||||||
|
id = qRegisterMetaType<T>();
|
||||||
|
}
|
||||||
|
eng->registerCustomType(id, toScriptValue,
|
||||||
|
fromScriptValue);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
template <typename T>
|
template <typename T>
|
||||||
int scriptRegisterMetaTypeWithLambdas(ScriptEngine* eng,
|
int scriptRegisterMetaTypeWithLambdas(ScriptEngine* eng,
|
||||||
ScriptValue (*toScriptValue)(ScriptEngine*, const T& t),
|
ScriptValue (*toScriptValue)(ScriptEngine*, const T& t),
|
||||||
|
@ -112,7 +131,7 @@ int scriptRegisterMetaTypeWithLambdas(ScriptEngine* eng,
|
||||||
eng->registerCustomType(id, reinterpret_cast<ScriptEngine::MarshalFunction>(toScriptValue),
|
eng->registerCustomType(id, reinterpret_cast<ScriptEngine::MarshalFunction>(toScriptValue),
|
||||||
reinterpret_cast<ScriptEngine::DemarshalFunction>(fromScriptValue));
|
reinterpret_cast<ScriptEngine::DemarshalFunction>(fromScriptValue));
|
||||||
return id;
|
return id;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
template <class Container>
|
template <class Container>
|
||||||
ScriptValue scriptValueFromSequence(ScriptEngine* eng, const Container& cont) {
|
ScriptValue scriptValueFromSequence(ScriptEngine* eng, const Container& cont) {
|
||||||
|
|
Loading…
Reference in a new issue