mirror of
https://github.com/overte-org/overte.git
synced 2025-04-11 13:42:38 +02:00
Fixes to scripting-related warnings (lambdas)
This commit is contained in:
parent
6f32173025
commit
b00c1ae91b
2 changed files with 32 additions and 15 deletions
|
@ -328,13 +328,17 @@ namespace scriptable {
|
|||
scriptRegisterSequenceMetaType<QVector<QPointer<T>>>(engine);
|
||||
return scriptRegisterMetaTypeWithLambdas<QPointer<T>>(
|
||||
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) {
|
||||
return engine->nullValue();
|
||||
}
|
||||
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();
|
||||
#ifdef SCRIPTABLE_MESH_DEBUG
|
||||
qCInfo(graphics_scripting) << "qpointer_qobject_cast" << obj << value.toString();
|
||||
|
@ -670,24 +674,18 @@ namespace scriptable {
|
|||
static const DebugEnums<T>& instance = debugEnums;
|
||||
return scriptRegisterMetaTypeWithLambdas<T>(
|
||||
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));
|
||||
},
|
||||
[](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());
|
||||
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;
|
||||
}
|
||||
|
||||
// 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>
|
||||
int scriptRegisterMetaTypeWithLambdas(ScriptEngine* eng,
|
||||
ScriptValue (*toScriptValue)(ScriptEngine*, const T& t),
|
||||
|
@ -112,7 +131,7 @@ int scriptRegisterMetaTypeWithLambdas(ScriptEngine* eng,
|
|||
eng->registerCustomType(id, reinterpret_cast<ScriptEngine::MarshalFunction>(toScriptValue),
|
||||
reinterpret_cast<ScriptEngine::DemarshalFunction>(fromScriptValue));
|
||||
return id;
|
||||
}
|
||||
}*/
|
||||
|
||||
template <class Container>
|
||||
ScriptValue scriptValueFromSequence(ScriptEngine* eng, const Container& cont) {
|
||||
|
|
Loading…
Reference in a new issue