|
QLua
Lua-Qt bindings
|
00001 #pragma once 00002 // QLua - Copyright (c) 2012, Ugo Varetto 00003 // All rights reserved. 00004 // 00005 // Redistribution and use in source and binary forms, with or without 00006 // modification, are permitted provided that the following conditions are met: 00007 // * Redistributions of source code must retain the above copyright 00008 // notice, this list of conditions and the following disclaimer. 00009 // * Redistributions in binary form must reproduce the above copyright 00010 // notice, this list of conditions and the following disclaimer in the 00011 // documentation and/or other materials provided with the distribution. 00012 // * Neither the name of the <organization> nor the 00013 // names of its contributors may be used to endorse or promote products 00014 // derived from this software without specific prior written permission. 00015 // 00016 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00017 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00018 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 // DISCLAIMED. IN NO EVENT SHALL UGO VARETTO BE LIABLE FOR ANY 00020 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00021 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00022 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00023 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00025 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 00030 00031 extern "C" { 00032 #include "lua.h" 00033 #include "lauxlib.h" 00034 #include "lualib.h" 00035 } 00036 00037 #include <QString> 00038 #include <QVariantMap> 00039 #include <QVariantList> 00040 #include <QString> 00041 #include <QList> 00042 #include <QGenericArgument> 00043 #include <QGenericReturnArgument> 00044 #include <QVector> 00045 00046 #include "LuaQtTypes.h" 00047 00049 namespace qlua { 00050 00051 //------------------------------------------------------------------------------ 00059 struct QArgConstructor { 00061 virtual QGenericArgument Create( lua_State*, int ) const = 0; 00063 virtual ~QArgConstructor() {} 00065 virtual QArgConstructor* Clone() const = 0; 00066 00067 }; 00069 class IntQArgConstructor : public QArgConstructor { 00070 public: 00077 QGenericArgument Create( lua_State* L, int idx ) const { 00078 i_ = luaL_checkint( L, idx ); 00079 return Q_ARG( int, i_ ); 00080 } 00082 IntQArgConstructor* Clone() const { 00083 return new IntQArgConstructor( *this ); 00084 } 00085 private: 00087 mutable int i_; 00088 }; 00090 class FloatQArgConstructor : public QArgConstructor { 00091 public: 00099 QGenericArgument Create( lua_State* L, int idx ) const { 00100 f_ = float( luaL_checknumber( L, idx ) ); 00101 return Q_ARG( double, f_ ); 00102 } 00104 FloatQArgConstructor* Clone() const { 00105 return new FloatQArgConstructor( *this ); 00106 } 00107 private: 00109 mutable float f_; 00110 }; 00112 class DoubleQArgConstructor : public QArgConstructor { 00113 public: 00120 QGenericArgument Create( lua_State* L, int idx ) const { 00121 d_ = luaL_checknumber( L, idx ); 00122 return Q_ARG( double, d_ ); 00123 } 00125 DoubleQArgConstructor* Clone() const { 00126 return new DoubleQArgConstructor( *this ); 00127 } 00128 private: 00130 mutable double d_; 00131 }; 00133 class StringQArgConstructor : public QArgConstructor { 00134 public: 00142 QGenericArgument Create( lua_State* L, int idx ) const { 00143 s_ = luaL_checkstring( L, idx ); 00144 return Q_ARG( QString, s_ ); 00145 } 00147 StringQArgConstructor* Clone() const { 00148 return new StringQArgConstructor( *this ); 00149 } 00150 private: 00152 mutable QString s_; 00153 }; 00155 class VariantMapQArgConstructor : public QArgConstructor { 00156 public: 00166 QGenericArgument Create( lua_State* L, int idx ) const { 00167 vm_ = ParseLuaTable( L, idx ); 00168 return Q_ARG( QVariantMap, vm_ ); 00169 } 00171 VariantMapQArgConstructor* Clone() const { 00172 return new VariantMapQArgConstructor( *this ); 00173 } 00174 private: 00176 mutable QVariantMap vm_; 00177 }; 00179 class VariantListQArgConstructor : public QArgConstructor { 00180 public: 00190 QGenericArgument Create( lua_State* L, int idx ) const { 00191 vl_ = ParseLuaTableAsVariantList( L, idx ); 00192 return Q_ARG( QVariantList, vl_ ); 00193 } 00195 VariantListQArgConstructor* Clone() const { 00196 return new VariantListQArgConstructor( *this ); 00197 } 00198 private: 00200 mutable QVariantList vl_; 00201 }; 00203 class ObjectStarQArgConstructor : public QArgConstructor { 00204 public: 00214 QGenericArgument Create( lua_State* L, int idx ) const { 00215 if( lua_istable( L, idx ) ) { 00216 lua_pushstring( L, "qobject__" ); 00217 lua_gettable( L, idx ); 00218 obj_ = *reinterpret_cast< QObject** >( lua_touserdata( L, -1 ) ); 00219 lua_pop( L, 1 ); 00220 } else if( lua_islightuserdata( L, idx ) ) { 00221 obj_ = reinterpret_cast< QObject* >( lua_touserdata( L, -1 ) ); 00222 } 00223 return Q_ARG( QObject*, obj_ ); 00224 } 00226 ObjectStarQArgConstructor* Clone() const { 00227 return new ObjectStarQArgConstructor( *this ); 00228 } 00229 private: 00231 mutable QObject* obj_; 00232 }; 00234 class WidgetStarQArgConstructor : public QArgConstructor { 00235 public: 00245 QGenericArgument Create( lua_State* L, int idx ) const { 00246 if( lua_istable( L, idx ) ) { 00247 lua_pushstring( L, "qobject__" ); 00248 lua_gettable( L, idx ); 00249 w_ = *reinterpret_cast< QWidget** >( lua_touserdata( L, -1 ) ); 00250 lua_pop( L, 1 ); 00251 } else if( lua_islightuserdata( L, idx ) ) { 00252 w_ = reinterpret_cast< QWidget* >( lua_touserdata( L, -1 ) ); 00253 } 00254 return Q_ARG( QWidget*, w_ ); 00255 } 00257 WidgetStarQArgConstructor* Clone() const { 00258 return new WidgetStarQArgConstructor( *this ); 00259 } 00260 private: 00262 mutable QWidget* w_; 00263 }; 00265 class VoidStarQArgConstructor : public QArgConstructor { 00266 public: 00273 QGenericArgument Create( lua_State* L, int idx ) const { 00274 v_ = const_cast< void* >( lua_topointer( L, idx ) ); 00275 return Q_ARG( void*, v_ ); 00276 } 00278 VoidStarQArgConstructor* Clone() const { 00279 return new VoidStarQArgConstructor( *this ); 00280 } 00281 private: 00283 mutable void* v_; 00284 }; 00286 template< typename T > 00287 class ListQArgConstructor : public QArgConstructor { 00288 public: 00303 QGenericArgument Create( lua_State* L, int idx ) const { 00304 l_ = ParseLuaTableAsNumberList< T >( L, idx ); 00305 return Q_ARG( QList< T >, l_ ); 00306 } 00308 ListQArgConstructor* Clone() const { 00309 return new ListQArgConstructor< T >( *this ); 00310 } 00311 private: 00313 mutable QList< T > l_; 00314 }; 00316 template< typename T > 00317 class VectorQArgConstructor : public QArgConstructor { 00318 public: 00333 QGenericArgument Create( lua_State* L, int idx ) const { 00334 v_ = ParseLuaTableAsNumberVector< T >( L, idx ); 00335 return Q_ARG( QVector< T >, v_ ); 00336 } 00338 VectorQArgConstructor* Clone() const { 00339 return new VectorQArgConstructor< T >( *this ); 00340 } 00341 private: 00343 mutable QVector< T > v_; 00344 }; 00346 class StringListQArgConstructor : public QArgConstructor { 00347 public: 00354 QGenericArgument Create( lua_State* L, int idx ) const { 00355 l_ = ParseLuaTableAsStringList( L, idx ); 00356 return Q_ARG( QStringList, l_ ); 00357 } 00359 StringListQArgConstructor* Clone() const { 00360 return new StringListQArgConstructor( *this ); 00361 } 00362 private: 00364 mutable QStringList l_; 00365 }; 00366 //------------------------------------------------------------------------------ 00369 class LArgConstructor { 00370 public: 00373 virtual void Push( lua_State* ) const = 0; 00376 virtual void Push( lua_State* , void* ) const = 0; 00378 virtual ~LArgConstructor() {} 00380 virtual LArgConstructor* Clone() const = 0; 00382 virtual QMetaType::Type Type() const = 0; 00385 QGenericReturnArgument Argument() const { return ga_; } 00392 virtual bool IsQObjectPtr() const { return false; } 00393 protected: 00395 template < typename T > void SetArg( T& arg ) { 00396 ga_ = QReturnArgument< T >( QMetaType::typeName( Type() ), arg ); 00397 } 00399 QGenericReturnArgument ga_; // not private, breaks encapsulation 00400 }; 00402 class IntLArgConstructor : public LArgConstructor { 00403 public: 00404 IntLArgConstructor() { 00405 SetArg( i_ ); 00406 } 00407 IntLArgConstructor( const IntLArgConstructor& other ) : i_( other.i_ ) { 00408 SetArg( i_ ); 00409 } 00410 void Push( lua_State* L ) const { 00411 lua_pushinteger( L, i_ ); 00412 } 00413 void Push( lua_State* L, void* value ) const { 00414 lua_pushinteger( L, *reinterpret_cast< int* >( value ) ); 00415 } 00416 IntLArgConstructor* Clone() const { 00417 return new IntLArgConstructor( *this ); 00418 } 00419 QMetaType::Type Type() const { return QMetaType::Int; } 00420 private: 00421 int i_; 00422 }; 00424 class DoubleLArgConstructor : public LArgConstructor { 00425 public: 00426 DoubleLArgConstructor() { 00427 SetArg( d_ ); 00428 } 00429 DoubleLArgConstructor( const DoubleLArgConstructor& other ) : d_( other.d_ ) { 00430 SetArg( d_ ); 00431 } 00432 void Push( lua_State* L ) const { 00433 lua_pushnumber( L, d_ ); 00434 } 00435 void Push( lua_State* L, void* value ) const { 00436 lua_pushnumber( L, *reinterpret_cast< double* >( value ) ); 00437 } 00438 DoubleLArgConstructor* Clone() const { 00439 return new DoubleLArgConstructor( *this ); 00440 } 00441 QMetaType::Type Type() const { return QMetaType::Double; } 00442 private: 00443 double d_; 00444 }; 00446 class FloatLArgConstructor : public LArgConstructor { 00447 public: 00448 FloatLArgConstructor() { 00449 SetArg( f_ ); 00450 } 00451 FloatLArgConstructor( const FloatLArgConstructor& other ) : f_( other.f_ ) { 00452 SetArg( f_ ); 00453 } 00454 void Push( lua_State* L ) const { 00455 lua_pushnumber( L, f_ ); 00456 } 00457 void Push( lua_State* L, void* value ) const { 00458 lua_pushnumber( L, *reinterpret_cast< float* >( value ) ); 00459 } 00460 FloatLArgConstructor* Clone() const { 00461 return new FloatLArgConstructor( *this ); 00462 } 00463 QMetaType::Type Type() const { return QMetaType::Float; } 00464 private: 00465 float f_; 00466 }; 00468 class StringLArgConstructor : public LArgConstructor { 00469 public: 00470 StringLArgConstructor() { 00471 SetArg( s_ ); 00472 } 00473 StringLArgConstructor( const StringLArgConstructor& other ) : s_( other.s_ ) { 00474 SetArg( s_ ); 00475 } 00476 void Push( lua_State* L ) const { 00477 lua_pushstring( L, s_.toAscii().constData() ); 00478 } 00479 void Push( lua_State* L, void* value ) const { 00480 lua_pushstring( L, reinterpret_cast< QString* >( value )->toAscii().constData() ); 00481 } 00482 StringLArgConstructor* Clone() const { 00483 return new StringLArgConstructor( *this ); 00484 } 00485 QMetaType::Type Type() const { return QMetaType::QString; } 00486 private: 00487 QString s_; 00488 }; 00490 class VoidLArgConstructor : public LArgConstructor { 00491 public: 00492 void Push( lua_State* ) const {} 00493 void Push( lua_State*, void* ) const {} 00494 VoidLArgConstructor* Clone() const { 00495 return new VoidLArgConstructor( *this ); 00496 } 00497 QMetaType::Type Type() const { return QMetaType::Void; } 00498 }; 00500 class VariantMapLArgConstructor : public LArgConstructor { 00501 public: 00502 VariantMapLArgConstructor() { 00503 SetArg( vm_ ); 00504 } 00505 VariantMapLArgConstructor( const VariantMapLArgConstructor& other ) : vm_( other.vm_ ) { 00506 SetArg( vm_ ); 00507 } 00508 void Push( lua_State* L ) const { 00509 VariantMapToLuaTable( vm_, L ); 00510 } 00511 void Push( lua_State* L, void* value ) const { 00512 VariantMapToLuaTable( *reinterpret_cast< QVariantMap* >( value ), L ); 00513 } 00514 VariantMapLArgConstructor* Clone() const { 00515 return new VariantMapLArgConstructor( *this ); 00516 } 00517 QMetaType::Type Type() const { return QMetaType::QVariantMap; } 00518 private: 00519 QVariantMap vm_; 00520 }; 00522 class VariantListLArgConstructor : public LArgConstructor { 00523 public: 00524 VariantListLArgConstructor() { 00525 SetArg( vl_ ); 00526 } 00527 VariantListLArgConstructor( const VariantListLArgConstructor& other ) : vl_( other.vl_ ) { 00528 SetArg( vl_ ); 00529 } 00530 void Push( lua_State* L ) const { 00531 VariantListToLuaTable( vl_, L ); 00532 } 00533 void Push( lua_State* L, void* value ) const { 00534 VariantListToLuaTable( *reinterpret_cast< QVariantList* >( value ), L ); 00535 } 00536 VariantListLArgConstructor* Clone() const { 00537 return new VariantListLArgConstructor( *this ); 00538 } 00539 QMetaType::Type Type() const { return QMetaType::QVariantList; } 00540 private: 00541 QVariantList vl_; 00542 }; 00544 class ObjectStarLArgConstructor : public LArgConstructor { 00545 public: 00546 ObjectStarLArgConstructor() { 00547 SetArg( obj_ ); 00548 } 00549 ObjectStarLArgConstructor( const ObjectStarLArgConstructor& other ) : obj_( other.obj_ ) { 00550 SetArg( obj_ ); 00551 } 00552 void Push( lua_State* L ) const { 00553 lua_pushlightuserdata( L, obj_ ); 00554 } 00555 void Push( lua_State* L, void* value ) const { 00556 lua_pushlightuserdata( L, value ); 00557 } 00558 ObjectStarLArgConstructor* Clone() const { 00559 return new ObjectStarLArgConstructor( *this ); 00560 } 00561 bool IsQObjectPtr() const { return true; } 00562 QMetaType::Type Type() const { return QMetaType::QObjectStar; } 00563 private: 00564 QObject* obj_; 00565 }; 00567 class WidgetStarLArgConstructor : public LArgConstructor { 00568 public: 00569 WidgetStarLArgConstructor() { 00570 SetArg( w_ ); 00571 } 00572 WidgetStarLArgConstructor( const WidgetStarLArgConstructor& other ) : w_( other.w_ ) { 00573 SetArg( w_ ); 00574 } 00575 void Push( lua_State* L ) const { 00576 lua_pushlightuserdata( L, w_ ); 00577 } 00578 void Push( lua_State* L, void* value ) const { 00579 lua_pushlightuserdata( L, value ); 00580 } 00581 WidgetStarLArgConstructor* Clone() const { 00582 return new WidgetStarLArgConstructor( *this ); 00583 } 00584 bool IsQObjectPtr() const { return true; } 00585 QMetaType::Type Type() const { return QMetaType::QWidgetStar; } 00586 private: 00587 QWidget* w_; 00588 }; 00590 class VoidStarLArgConstructor : public LArgConstructor { 00591 public: 00592 VoidStarLArgConstructor() { 00593 SetArg( v_ ); 00594 } 00595 VoidStarLArgConstructor( const VoidStarLArgConstructor& other ) : v_( other.v_ ) { 00596 SetArg( v_ ); 00597 } 00598 void Push( lua_State* L ) const { 00599 lua_pushlightuserdata( L, v_ ); 00600 } 00601 void Push( lua_State* L, void* value ) const { 00602 lua_pushlightuserdata( L, value ); 00603 } 00604 VoidStarLArgConstructor* Clone() const { 00605 return new VoidStarLArgConstructor( *this ); 00606 } 00607 QMetaType::Type Type() const { return QMetaType::VoidStar; } 00608 private: 00609 void* v_; 00610 }; 00618 template < typename T > 00619 class ListLArgConstructor : public LArgConstructor { 00620 public: 00621 ListLArgConstructor() { 00622 SetArg( l_ ); 00623 } 00624 ListLArgConstructor( const ListLArgConstructor& other ) : l_( other.l_ ) { 00625 SetArg( l_ ); 00626 } 00627 void Push( lua_State* L ) const { 00628 NumberListToLuaTable< T >( l_, L ); 00629 } 00630 void Push( lua_State* L, void* value ) const { 00631 NumberListToLuaTable< T >( *reinterpret_cast< QList< T >* >( value ), L ); 00632 } 00633 ListLArgConstructor* Clone() const { 00634 return new ListLArgConstructor( *this ); 00635 } 00636 QMetaType::Type Type() const { return QMetaType::Type( QMetaType::type( TypeName< QList< T > >() ) ); } 00637 private: 00638 QList< T > l_; 00639 }; 00647 template < typename T > 00648 class VectorLArgConstructor : public LArgConstructor { 00649 public: 00650 VectorLArgConstructor() { 00651 SetArg( v_ ); 00652 } 00653 VectorLArgConstructor( const VectorLArgConstructor& other ) : v_( other.v_ ) { 00654 SetArg( v_ ); 00655 } 00656 void Push( lua_State* L ) const { 00657 NumberVectorToLuaTable< T >( v_, L ); 00658 } 00659 void Push( lua_State* L, void* value ) const { 00660 NumberVectorToLuaTable< T >( *reinterpret_cast< QVector< T >* >( value ), L ); 00661 } 00662 VectorLArgConstructor* Clone() const { 00663 return new VectorLArgConstructor( *this ); 00664 } 00665 QMetaType::Type Type() const { return QMetaType::Type( QMetaType::type( TypeName< QVector< T > >() ) ); } 00666 private: 00667 QVector< T > v_; 00668 }; 00670 class StringListLArgConstructor : public LArgConstructor { 00671 public: 00672 StringListLArgConstructor() { 00673 SetArg( l_ ); 00674 } 00675 StringListLArgConstructor( const StringListLArgConstructor& other ) : l_( other.l_ ) { 00676 SetArg( l_ ); 00677 } 00678 void Push( lua_State* L ) const { 00679 StringListToLuaTable( l_, L ); 00680 } 00681 void Push( lua_State* L, void* value ) const { 00682 StringListToLuaTable( *reinterpret_cast< QStringList* >( value ), L ); 00683 } 00684 StringListLArgConstructor* Clone() const { 00685 return new StringListLArgConstructor( *this ); 00686 } 00687 QMetaType::Type Type() const { return QMetaType::Type( QMetaType::type( TypeName< QList< QString > >() ) ); } 00688 private: 00689 QStringList l_; 00690 }; 00691 00692 //------------------------------------------------------------------------------ 00703 class QArgWrapper { 00704 public: 00706 QArgWrapper() : ac_( 0 ) {} 00708 QArgWrapper( const QArgWrapper& other ) : ac_( 0 ) { 00709 if( other.ac_ ) ac_ = other.ac_->Clone(); 00710 } 00713 QArgWrapper( const QString& type ) : ac_( 0 ) { 00714 if( type == QMetaType::typeName( QMetaType::Int ) ) { 00715 ac_ = new IntQArgConstructor; 00716 } else if( type == QMetaType::typeName( QMetaType::Double ) ) { 00717 ac_ = new DoubleQArgConstructor; 00718 } else if( type == QMetaType::typeName( QMetaType::Float ) ) { 00719 ac_ = new FloatQArgConstructor; 00720 } else if( type == QMetaType::typeName( QMetaType::QString ) ) { 00721 ac_ = new StringQArgConstructor; 00722 } else if( type == QMetaType::typeName( QMetaType::QVariantMap ) ) { 00723 ac_ = new VariantMapQArgConstructor; 00724 } else if( type == QMetaType::typeName( QMetaType::QVariantList ) ) { 00725 ac_ = new VariantListQArgConstructor; 00726 } else if( type == QMetaType::typeName( QMetaType::QObjectStar ) ) { 00727 ac_ = new ObjectStarQArgConstructor; 00728 } else if( type == QMetaType::typeName( QMetaType::QStringList ) ) { 00729 ac_ = new StringListQArgConstructor; 00730 } else if( type == QMetaType::typeName( QMetaType::QWidgetStar ) ) { 00731 ac_ = new WidgetStarQArgConstructor; 00732 } else if( type == QMetaType::typeName( QMetaType::VoidStar ) ) { 00733 ac_ = new VoidStarQArgConstructor; 00734 } else if( type == QLUA_LIST_FLOAT64 ) { 00735 ac_ = new ListQArgConstructor< double >; 00736 } else if( type == QLUA_LIST_FLOAT32 ) { 00737 ac_ = new ListQArgConstructor< float >; 00738 } else if( type == QLUA_LIST_INT ) { 00739 ac_ = new ListQArgConstructor< int >; 00740 } else if( type == QLUA_LIST_SHORT ) { 00741 ac_ = new ListQArgConstructor< short >; 00742 } else if( type == QLUA_VECTOR_FLOAT64 ) { 00743 ac_ = new VectorQArgConstructor< double >; 00744 } else if( type == QLUA_VECTOR_FLOAT32 ) { 00745 ac_ = new VectorQArgConstructor< float >; 00746 } else if( type == QLUA_VECTOR_INT ) { 00747 ac_ = new VectorQArgConstructor< int >; 00748 } else if( type == QLUA_VECTOR_SHORT ) { 00749 ac_ = new VectorQArgConstructor< short >; 00750 } else throw std::logic_error( ( "Type " + type + " unknown" ).toStdString() ); 00751 } 00756 QGenericArgument Arg( lua_State* L, int idx ) const { 00757 return ac_ ? ac_->Create( L, idx ) : QGenericArgument(); 00758 } 00760 ~QArgWrapper() { delete ac_; } 00761 private: 00764 QArgConstructor* ac_; 00765 }; 00766 00774 class LArgWrapper { 00775 public: 00777 LArgWrapper() : ac_( 0 ) {} 00779 LArgWrapper( const LArgWrapper& other ) : ac_( 0 ), type_( other.type_ ) { 00780 if( other.ac_ ) ac_ = other.ac_->Clone(); 00781 } 00785 LArgWrapper( const QString& type ) : ac_( 0 ), type_( type ) { 00786 if( type_ == QMetaType::typeName( QMetaType::Int ) ) { 00787 ac_ = new IntLArgConstructor; 00788 } else if( type == QMetaType::typeName( QMetaType::Double ) ) { 00789 ac_ = new DoubleLArgConstructor; 00790 } else if( type == QMetaType::typeName( QMetaType::Float ) ) { 00791 ac_ = new FloatLArgConstructor; 00792 } else if( type_ == QMetaType::typeName( QMetaType::QString ) ) { 00793 ac_ = new StringLArgConstructor; 00794 } else if( type_ == QMetaType::typeName( QMetaType::QVariantMap ) ) { 00795 ac_ = new VariantMapLArgConstructor; 00796 } else if( type_ == QMetaType::typeName( QMetaType::QVariantList ) ) { 00797 ac_ = new VariantListLArgConstructor; 00798 } else if( type == QMetaType::typeName( QMetaType::QObjectStar ) ) { 00799 ac_ = new ObjectStarLArgConstructor; 00800 } else if( type == QMetaType::typeName( QMetaType::QStringList ) ) { 00801 ac_ = new StringListLArgConstructor; 00802 } else if( type == QMetaType::typeName( QMetaType::QWidgetStar ) ) { 00803 ac_ = new WidgetStarLArgConstructor; 00804 } else if( type == QMetaType::typeName( QMetaType::VoidStar ) ) { 00805 ac_ = new VoidStarLArgConstructor; 00806 } else if( type == QLUA_LIST_FLOAT64 ) { 00807 ac_ = new ListLArgConstructor< double >; 00808 } else if( type == QLUA_LIST_FLOAT32 ) { 00809 ac_ = new ListLArgConstructor< float >; 00810 } else if( type == QLUA_LIST_INT ) { 00811 ac_ = new ListLArgConstructor< int >; 00812 } else if( type == QLUA_LIST_SHORT ) { 00813 ac_ = new ListLArgConstructor< short >; 00814 } else if( type == QLUA_VECTOR_FLOAT64 ) { 00815 ac_ = new VectorLArgConstructor< double >; 00816 } else if( type == QLUA_VECTOR_FLOAT32 ) { 00817 ac_ = new VectorLArgConstructor< float >; 00818 } else if( type == QLUA_VECTOR_INT ) { 00819 ac_ = new VectorLArgConstructor< int >; 00820 } else if( type == QLUA_VECTOR_SHORT ) { 00821 ac_ = new VectorLArgConstructor< short >; 00822 } else if( type_.isEmpty() ) ac_ = new VoidLArgConstructor; 00823 else throw std::logic_error( ( "Type " + type + " unknown" ).toStdString() ); 00824 } 00829 void Push( lua_State* L ) const { 00830 ac_->Push( L ); 00831 } 00841 void Push( lua_State* L, void* value ) const { 00842 ac_->Push( L, value ); // called from the callback dispatcher method 00843 } 00852 QGenericReturnArgument Arg() const { return ac_->Argument(); } 00854 const QString& Type() const { 00855 return type_; 00856 } 00858 QMetaType::Type MetaType() const { return ac_->Type(); } 00860 bool IsQObjectPtr() const { return ac_->IsQObjectPtr(); } 00862 ~LArgWrapper() { delete ac_; } 00863 private: 00865 LArgConstructor* ac_; 00867 QString type_; 00868 }; 00869 00870 typedef QList< QArgWrapper > QArgWrappers; 00871 typedef QList< QByteArray > ArgumentTypes; 00872 00875 inline QArgWrappers GenerateQArgWrappers( const ArgumentTypes& at ) { 00876 QArgWrappers aw; 00877 for( ArgumentTypes::const_iterator i = at.begin(); i != at.end(); ++i ) { 00878 aw.push_back( QArgWrapper( *i ) ); 00879 } 00880 return aw; 00881 } 00883 inline LArgWrapper GenerateLArgWrapper( const QString& typeName ) { 00884 return LArgWrapper( typeName ); 00885 } 00886 00887 }
1.7.4