scriptified remaining default null types
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Thu, 21 Oct 2010 12:47:22 +0000 (12:47 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Thu, 21 Oct 2010 12:47:22 +0000 (12:47 +0000)
git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@606 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

qtbase/src/nullscript.cpp
woc/qt/qtout.cpp

index 5d18d55..2573801 100644 (file)
@@ -31,12 +31,84 @@ static void String_fromScriptValue(const QScriptValue&val,Nullable<QString>&obj)
        else obj=Nullable<QString>();
 }
 
+static QScriptValue Int32_toScriptValue(QScriptEngine*,const Nullable<qint32>&obj)
+{
+       if(obj.isNull())return QScriptValue::NullValue;
+       else return QScriptValue(obj.value());
+}
+
+static void Int32_fromScriptValue(const QScriptValue&val,Nullable<qint32>&obj)
+{
+       if(val.isNull())obj=Nullable<qint32>();
+       if(val.isNumber())obj=val.toInt32();
+       else obj=Nullable<qint32>();
+}
+
+static QScriptValue UInt32_toScriptValue(QScriptEngine*,const Nullable<quint32>&obj)
+{
+       if(obj.isNull())return QScriptValue::NullValue;
+       else return QScriptValue(obj.value());
+}
+
+static void UInt32_fromScriptValue(const QScriptValue&val,Nullable<quint32>&obj)
+{
+       if(val.isNull())obj=Nullable<quint32>();
+       if(val.isNumber())obj=val.toUInt32();
+       else obj=Nullable<quint32>();
+}
+
+static QScriptValue Int64_toScriptValue(QScriptEngine*,const Nullable<qint64>&obj)
+{
+       if(obj.isNull())return QScriptValue::NullValue;
+       else return QScriptValue(qsreal(obj.value()));
+}
+
+static void Int64_fromScriptValue(const QScriptValue&val,Nullable<qint64>&obj)
+{
+       if(val.isNull())obj=Nullable<qint64>();
+       if(val.isNumber())obj=(qint64)val.toNumber();
+       else obj=Nullable<qint64>();
+}
+
+static QScriptValue UInt64_toScriptValue(QScriptEngine*,const Nullable<quint64>&obj)
+{
+       if(obj.isNull())return QScriptValue::NullValue;
+       else return QScriptValue(qsreal(obj.value()));
+}
+
+static void UInt64_fromScriptValue(const QScriptValue&val,Nullable<quint64>&obj)
+{
+       if(val.isNull())obj=Nullable<quint64>();
+       if(val.isNumber())obj=(quint64)val.toNumber();
+       else obj=Nullable<quint64>();
+}
+
+//TODO: copy the QByteArray wrapper from the Qt tutorials
+static QScriptValue BA_toScriptValue(QScriptEngine*engine,const Nullable<QByteArray>&obj)
+{
+       if(obj.isNull())return QScriptValue::NullValue;
+       else return engine->newVariant(obj.value());
+}
+
+static void BA_fromScriptValue(const QScriptValue&val,Nullable<QByteArray>&obj)
+{
+       if(val.isNull())obj=Nullable<QByteArray>();
+       if(val.isVariant())obj=val.toVariant().toByteArray();
+       else obj=Nullable<QByteArray>();
+}
+
+
 //list of supported types
 static void initNullableScripting(QScriptEngine*engine)
 {
        QScriptValue gval=engine->globalObject();
        qScriptRegisterMetaType(engine,Bool_toScriptValue,Bool_fromScriptValue);
        qScriptRegisterMetaType(engine,String_toScriptValue,String_fromScriptValue);
+       qScriptRegisterMetaType(engine,Int32_toScriptValue,Int32_fromScriptValue);
+       qScriptRegisterMetaType(engine,UInt32_toScriptValue,UInt32_fromScriptValue);
+       qScriptRegisterMetaType(engine,Int64_toScriptValue,Int64_fromScriptValue);
+       qScriptRegisterMetaType(engine,UInt64_toScriptValue,UInt64_fromScriptValue);
+       qScriptRegisterMetaType(engine,BA_toScriptValue,BA_fromScriptValue);
 }
 
 
index eb237fb..c053184 100644 (file)
@@ -261,7 +261,8 @@ void WocQtOut::initScripting()
        nscr.close();
        //initializer routine
        m_scriptcode+="void "+ifaceClassName()+"::initScriptEngine(QScriptEngine*engine)\n{\n";
-       m_scriptcode+="\tQScriptValue gval=engine->globalObject();\n";
+       m_scriptcode+="\tQScriptValue gval=engine->newObject();\n";
+       m_scriptcode+="\tengine->globalObject().setProperty(\"wob\",gval);\n";
        //register interfacce itself
        m_scriptcode+="\tgval.setProperty(\"Interface\",engine->newQMetaObject(this->metaObject()));\n";
        m_scriptcode+="\tgval.setProperty(\"interface\",engine->newQObject(this,QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater));\n";