From 6ccf59730682f6e0fc643a00090f4acb11f38764 Mon Sep 17 00:00:00 2001 From: konrad Date: Thu, 21 Oct 2010 12:47:22 +0000 Subject: [PATCH] scriptified remaining default null types git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@606 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- qtbase/src/nullscript.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++ woc/qt/qtout.cpp | 3 +- 2 files changed, 74 insertions(+), 1 deletions(-) diff --git a/qtbase/src/nullscript.cpp b/qtbase/src/nullscript.cpp index 5d18d55..2573801 100644 --- a/qtbase/src/nullscript.cpp +++ b/qtbase/src/nullscript.cpp @@ -31,12 +31,84 @@ static void String_fromScriptValue(const QScriptValue&val,Nullable&obj) else obj=Nullable(); } +static QScriptValue Int32_toScriptValue(QScriptEngine*,const Nullable&obj) +{ + if(obj.isNull())return QScriptValue::NullValue; + else return QScriptValue(obj.value()); +} + +static void Int32_fromScriptValue(const QScriptValue&val,Nullable&obj) +{ + if(val.isNull())obj=Nullable(); + if(val.isNumber())obj=val.toInt32(); + else obj=Nullable(); +} + +static QScriptValue UInt32_toScriptValue(QScriptEngine*,const Nullable&obj) +{ + if(obj.isNull())return QScriptValue::NullValue; + else return QScriptValue(obj.value()); +} + +static void UInt32_fromScriptValue(const QScriptValue&val,Nullable&obj) +{ + if(val.isNull())obj=Nullable(); + if(val.isNumber())obj=val.toUInt32(); + else obj=Nullable(); +} + +static QScriptValue Int64_toScriptValue(QScriptEngine*,const Nullable&obj) +{ + if(obj.isNull())return QScriptValue::NullValue; + else return QScriptValue(qsreal(obj.value())); +} + +static void Int64_fromScriptValue(const QScriptValue&val,Nullable&obj) +{ + if(val.isNull())obj=Nullable(); + if(val.isNumber())obj=(qint64)val.toNumber(); + else obj=Nullable(); +} + +static QScriptValue UInt64_toScriptValue(QScriptEngine*,const Nullable&obj) +{ + if(obj.isNull())return QScriptValue::NullValue; + else return QScriptValue(qsreal(obj.value())); +} + +static void UInt64_fromScriptValue(const QScriptValue&val,Nullable&obj) +{ + if(val.isNull())obj=Nullable(); + if(val.isNumber())obj=(quint64)val.toNumber(); + else obj=Nullable(); +} + +//TODO: copy the QByteArray wrapper from the Qt tutorials +static QScriptValue BA_toScriptValue(QScriptEngine*engine,const Nullable&obj) +{ + if(obj.isNull())return QScriptValue::NullValue; + else return engine->newVariant(obj.value()); +} + +static void BA_fromScriptValue(const QScriptValue&val,Nullable&obj) +{ + if(val.isNull())obj=Nullable(); + if(val.isVariant())obj=val.toVariant().toByteArray(); + else obj=Nullable(); +} + + //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); } diff --git a/woc/qt/qtout.cpp b/woc/qt/qtout.cpp index eb237fb..c053184 100644 --- a/woc/qt/qtout.cpp +++ b/woc/qt/qtout.cpp @@ -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"; -- 1.7.2.5