mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-19 16:40:22 +02:00
Support functions in QScript contexts
This commit is contained in:
parent
58d3578fb1
commit
3ca3c635c0
1 changed files with 24 additions and 0 deletions
|
@ -59,6 +59,25 @@ namespace controller {
|
||||||
QJSValue _callable;
|
QJSValue _callable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ScriptEndpoint : public Endpoint {
|
||||||
|
public:
|
||||||
|
ScriptEndpoint(const QScriptValue& callable)
|
||||||
|
: Endpoint(UserInputMapper::Input(-1)), _callable(callable) {
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual float value() {
|
||||||
|
float result = (float)_callable.call().toNumber();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void apply(float newValue, float oldValue, const Pointer& source) {
|
||||||
|
_callable.call(QScriptValue(), QScriptValueList({ QScriptValue(newValue) }));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QScriptValue _callable;
|
||||||
|
};
|
||||||
|
|
||||||
class CompositeEndpoint : public Endpoint, Endpoint::Pair {
|
class CompositeEndpoint : public Endpoint, Endpoint::Pair {
|
||||||
public:
|
public:
|
||||||
CompositeEndpoint(Endpoint::Pointer first, Endpoint::Pointer second)
|
CompositeEndpoint(Endpoint::Pointer first, Endpoint::Pointer second)
|
||||||
|
@ -297,6 +316,11 @@ namespace controller {
|
||||||
return endpointFor(UserInputMapper::Input(endpoint.toInt32()));
|
return endpointFor(UserInputMapper::Input(endpoint.toInt32()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (endpoint.isFunction()) {
|
||||||
|
auto result = std::make_shared<ScriptEndpoint>(endpoint);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
qWarning() << "Unsupported input type " << endpoint.toString();
|
qWarning() << "Unsupported input type " << endpoint.toString();
|
||||||
return Endpoint::Pointer();
|
return Endpoint::Pointer();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue