From 8cb3f792f60792647b87226cbae455d46d16d217 Mon Sep 17 00:00:00 2001 From: konrad Date: Thu, 21 Oct 2010 11:56:13 +0000 Subject: [PATCH] make some nullables scriptable remove bogus shortcut types git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@605 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- qtbase/include/nullable.h | 23 +++++++++++------------ qtbase/src/nullscript.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ qtbase/src/object.cpp | 14 +++++++------- woc/qt/qtfiles.qrc | 6 ++++++ woc/qt/qtout.cpp | 24 +++++++++++++++++++----- woc/qt/qtout.h | 2 ++ woc/woc.pro | 2 ++ 7 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 qtbase/src/nullscript.cpp create mode 100644 woc/qt/qtfiles.qrc diff --git a/qtbase/include/nullable.h b/qtbase/include/nullable.h index 304168a..4417e7b 100644 --- a/qtbase/include/nullable.h +++ b/qtbase/include/nullable.h @@ -64,18 +64,17 @@ templateclass Nullable #include #include //convenience wrappers -typedef Nullable Bool;Q_DECLARE_METATYPE(Bool) -typedef Nullable Int; -typedef Nullable Int32;Q_DECLARE_METATYPE(Int32) -typedef Nullable Int64;Q_DECLARE_METATYPE(Int64) -typedef Nullable UInt32;Q_DECLARE_METATYPE(UInt32) -typedef Nullable UInt64;Q_DECLARE_METATYPE(UInt64) -typedef Nullable NString;Q_DECLARE_METATYPE(NString) -typedef Nullable NByteArray;Q_DECLARE_METATYPE(NByteArray) +Q_DECLARE_METATYPE(Nullable) +Q_DECLARE_METATYPE(Nullable) +Q_DECLARE_METATYPE(Nullable) +Q_DECLARE_METATYPE(Nullable) +Q_DECLARE_METATYPE(Nullable) +Q_DECLARE_METATYPE(Nullable) +Q_DECLARE_METATYPE(Nullable) -inline bool operator==(Int64 i1,int i2){return i1.operator==(i2);} -inline bool operator==(UInt32 i1,int i2){return i1.operator==(i2);} -inline bool operator==(UInt64 i1,int i2){return i1.operator==(i2);} -inline bool operator==(UInt64 i1,unsigned int i2){return i1.operator==(i2);} +inline bool operator==(Nullable i1,int i2){return i1.operator==(i2);} +inline bool operator==(Nullable i1,int i2){return i1.operator==(i2);} +inline bool operator==(Nullable i1,int i2){return i1.operator==(i2);} +inline bool operator==(Nullable i1,unsigned int i2){return i1.operator==(i2);} #endif diff --git a/qtbase/src/nullscript.cpp b/qtbase/src/nullscript.cpp new file mode 100644 index 0000000..5d18d55 --- /dev/null +++ b/qtbase/src/nullscript.cpp @@ -0,0 +1,43 @@ +//start: nullscript.cpp +//currently this file is copied verbatim into the generated +//interface code, in the future it may be included here instead + +#include +#include + +static QScriptValue Bool_toScriptValue(QScriptEngine*,const Nullable&obj) +{ + if(obj.isNull())return QScriptValue::NullValue; + else return QScriptValue(obj.value()); +} + +static void Bool_fromScriptValue(const QScriptValue&val,Nullable&obj) +{ + if(val.isNull())obj=Nullable(); + if(val.isBool())obj=val.toBool(); + else obj=Nullable(); +} + +static QScriptValue String_toScriptValue(QScriptEngine*,const Nullable&obj) +{ + if(obj.isNull())return QScriptValue::NullValue; + else return QScriptValue(obj.value()); +} + +static void String_fromScriptValue(const QScriptValue&val,Nullable&obj) +{ + if(val.isNull())obj=Nullable(); + if(val.isString())obj=val.toString(); + 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); +} + + +//end: nullscript.cpp diff --git a/qtbase/src/object.cpp b/qtbase/src/object.cpp index ae172b8..eb0f93d 100644 --- a/qtbase/src/object.cpp +++ b/qtbase/src/object.cpp @@ -16,10 +16,10 @@ #include "Nullable" static int itype0= - qRegisterMetaType()+ - qRegisterMetaType()+ - qRegisterMetaType()+ - qRegisterMetaType()+ - qRegisterMetaType()+ - qRegisterMetaType()+ - qRegisterMetaType(); + qRegisterMetaType >()+ + qRegisterMetaType >()+ + qRegisterMetaType >()+ + qRegisterMetaType >()+ + qRegisterMetaType >()+ + qRegisterMetaType >()+ + qRegisterMetaType >(); diff --git a/woc/qt/qtfiles.qrc b/woc/qt/qtfiles.qrc new file mode 100644 index 0000000..1a13a3f --- /dev/null +++ b/woc/qt/qtfiles.qrc @@ -0,0 +1,6 @@ + + + + ../../qtbase/src/nullscript.cpp + + diff --git a/woc/qt/qtout.cpp b/woc/qt/qtout.cpp index 3cb9581..eb237fb 100644 --- a/woc/qt/qtout.cpp +++ b/woc/qt/qtout.cpp @@ -79,11 +79,7 @@ WocQtOut::WocQtOut(QDomElement&el) m_iface.write(QString(" Q_INVOKABLE static QString svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii()); //init scripting - m_scriptcode="#include \n"; - m_scriptcode+="void "+ifaceClassName()+"::initScriptEngine(QScriptEngine*engine)\n{\n"; - m_scriptcode+="\tQScriptValue gval=engine->globalObject();\n"; - m_scriptcode+="\tgval.setProperty(\"Interface\",engine->newQMetaObject(this->metaObject()));\n"; - m_scriptcode+="\tgval.setProperty(\"interface\",engine->newQObject(this,QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater));\n"; + initScripting(); //create all includer m_hdr.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"IncludeAll"); @@ -254,3 +250,21 @@ WocQtTransaction::WocQtTransaction(WocQtOut*p) { connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); } + +void WocQtOut::initScripting() +{ +// m_scriptcode="#include \n"; + //script converters for nullables + QFile nscr(":/nullscript.cpp");nscr.open(QIODevice::ReadOnly); + m_scriptcode+=QString::fromAscii(nscr.readAll()); + m_scriptcode+="\n\n"; + nscr.close(); + //initializer routine + m_scriptcode+="void "+ifaceClassName()+"::initScriptEngine(QScriptEngine*engine)\n{\n"; + m_scriptcode+="\tQScriptValue gval=engine->globalObject();\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"; + //register nullables + m_scriptcode+="\tinitNullableScripting(engine);\n"; +} diff --git a/woc/qt/qtout.h b/woc/qt/qtout.h index a4c83f6..85cabe8 100644 --- a/woc/qt/qtout.h +++ b/woc/qt/qtout.h @@ -88,6 +88,8 @@ class WocQtOut:public WocOutput void addScriptInit(QString s){m_scriptcode+=s;} ///helper: returns true if sub-classes are supposed to create scripting code bool doGenerateScripting()const{return m_genscript;} + ///internal: init the scripting env + void initScripting(); WocQtClass*qclass; WocQtTable*qtable; diff --git a/woc/woc.pro b/woc/woc.pro index 39ceeb8..d2a2aca 100644 --- a/woc/woc.pro +++ b/woc/woc.pro @@ -20,6 +20,8 @@ HEADERS+= \ htmlout.h \ mfile.h \ domquery.h + +RESOURCES += qt/qtfiles.qrc include(proc/proc.pri) include(php/php.pri) -- 1.7.2.5