Commit 6f2d5e2f authored by Jascha Wedowski's avatar Jascha Wedowski

script wrapper for DataType

parent 1bd829f2
Pipeline #7398 failed with stages
in 46 minutes and 1 second
......@@ -114,9 +114,11 @@ void ScriptingBackend::pluginsInitialized()
QJSValue createVector = jsEngine_->evaluate("function(x, y, z) { return ScriptVectorInterface.CreateVector(x, y, z); }");
QJSValue createVector4 = jsEngine_->evaluate("function(x, y, z, w) { return ScriptVectorInterface.CreateVector4(x, y, z, w); }");
QJSValue createMat4x4 = jsEngine_->evaluate("function() { return ScriptVectorInterface.CreateMatrix4x4(Array.prototype.slice.apply(arguments)); }");
QJSValue createDataType = jsEngine_->evaluate("function() { return ScriptVectorInterface.CreateDataType(Array.prototype.sclice.apply(arguments)); }");
jsEngine_->globalObject().setProperty("Vector", createVector);
jsEngine_->globalObject().setProperty("Vector4", createVector4);
jsEngine_->globalObject().setProperty("Matrix4x4", createMat4x4);
jsEngine_->globalObject().setProperty("DataType", createDataType);
}
void ScriptingBackend::slotExecuteScript(QString script)
......
......@@ -164,6 +164,7 @@ public slots:
#include <OpenFlipper/Scripting/scriptPrototypes/prototypeVec3d.hh>
#include <OpenFlipper/Scripting/scriptPrototypes/prototypeVec4d.hh>
#include <OpenFlipper/Scripting/scriptPrototypes/prototypeMatrix4x4.hh>
#include <OpenFlipper/Scripting/scriptPrototypes/prototypeDataType.hh>
#include <cstdio>
class ScriptVectorInterface : public QObject
......@@ -212,6 +213,25 @@ public:
return _engine->toScriptValue(result);
}
Q_INVOKABLE
QJSValue CreateDataType(QVariantList args)
{
DataType s;
if(args.size() != 1) {
s = DATA_UNKNOWN;
} else {
auto arg = args[0];
bool ok;
s = arg.toInt(&ok);
if(!ok) {
s = typeId(arg.toString());
}
}
ScriptDataType res(s);
return _engine->toScriptValue(s);
}
public slots:
void PrintVector(Vector vec)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment