示例#1
0
QVariant QuickInterpreter::call(QObject *ctx, const QString &func, const QVariantList &args)
{
    QSList l;
    for (int i=0; i<args.size(); ++i) {
        const QVariant &v = args.at(i);
	switch (v.type()) {
        case QMetaType::QObjectStar:
	    l.append(wrap(qvariant_cast<QObject *>(v)));
	    break;
	case QMetaType::VoidStar:
	    qWarning("QuickInterpreter::call: don't know what to do with a "
		      "QVariant::VoidPointer here...");
 	    break;
	default:
            {
                QuickScriptVariant qsvar(this, v);
                if (qsvar.isNative())
                    l.append(qsvar.toNative());
                else
                    l.append(qsvar);
                break;
            }
	}
    }
    return call(ctx, func, l);
}
示例#2
0
void qsa_slot_callback(QObject *_this, int callId, int paramCount,
                       const QMetaType::Type *types,
                       const QByteArray *typeNames,
                       void *argumentList[])
{
//     printf("qsa_slot_callback, id=%d\n", callId);

    QuickInterpreter *ip = static_cast<QuickInterpreter *>(_this);
    QSAConnection connection = ip->scriptSlot(callId);

    Q_ASSERT(connection.sender);
    Q_ASSERT(connection.signal.length());
    Q_ASSERT(connection.function_ref.isValid());

    QSEnv *env = ip->env();
    QSList arguments;

    for (int i=1; i<paramCount; ++i) {
        QSATypeInfo info;
        info.name = typeNames[i];
        info.id = types[i];

        QSObject val = convert_qt2qsa(env, argumentList[i], info, _this);
        Q_ASSERT(val.isValid());

        arguments.append(val);
    }

    QSObject func_base = QSFuncRefClass::refBase(connection.function_ref);
    QString func_name = QSFuncRefClass::refMember(connection.function_ref).name();

    ip->call(func_base, func_name, arguments);
}
QSArgument QuickInterpreter::call( QObject *ctx, const QString &func, const QSArgumentList &args )
{
    QSList l;
    for ( QSArgumentList::ConstIterator it = args.begin(); it != args.end(); ++it ) {
	switch ( (*it).type() ) {
	case QSArgument::Variant: {
            QuickScriptVariant qsvar(this, (*it).variant());
            if (qsvar.isNative())
                l.append(qsvar.toNative());
            else
                l.append(qsvar);
	    break;
	}
        case QSArgument::QObjectPtr:
	    l.append( wrap( (*it).qobject() ) );
	    break;
	case QSArgument::VoidPointer:
	    qWarning( "QuickInterpreter::call: don't know what to do with a "
		      "QSArgument::VoidPointer here..." );
 	    break;
	default:
	    break;
	}
    }
    return call( ctx, func, l );
}
示例#4
0
QSList *QSList::copy() const
{
    QSList *newList = new QSList();
    QSListIterator e = end();
    QSListIterator it = begin();

    while( it != e ) {
	newList->append( *it );
	++it;
    }

    return newList;
}
QSObject QSPointClass::construct(const QSList &args) const
{
  if (args.size() == 1) {
    if (args[ 0 ].objectType() == this) {
      QSObject pt = args.at(0);
      return construct(QPoint(*point(&pt)));
    }
  } else if (args.size() == 2) {
    return construct(QPoint(args[ 0 ].toInteger(), args[ 1 ].toInteger()));
  }

  return construct(QPoint());
}
QSObject QSSizeClass::construct(const QSList &args) const
{
  if (args.size() == 1) {
    if (args[ 0 ].objectType() == this) {
      QSObject sz = args.at(0);
      return construct(QSize(*size(&sz)));
    }
  } else if (args.size() == 2) {
    return construct(QSize(args[ 0 ].toInteger(),
                           args[ 1 ].toInteger()));
  }

  return construct(QSize());
}
示例#7
0
QSObject QSErrorClass::construct( const QSList &args ) const
{
    QString m = !args.isEmpty() && args[0].isDefined() ?
                args[0].toString() : QString::null;

    return construct( GeneralError, m );
}
示例#8
0
QSObject QSRegExpClass::construct( const QSList &args ) const
{
    // ### regexp arguments
    QString p = args.isEmpty() ? QString::fromLatin1( "" ) : args[0].toString();

    if (args.size() < 2) {
	QSRegExpShared *sh = new QSRegExpShared(p, FALSE, FALSE);
	return env()->createShared(this, sh);
    }

    QString flags = args[1].toString();
    bool ignoreCase = (flags.find(QString::fromLatin1("i")) >= 0);
    bool global = (flags.find(QString::fromLatin1("g")) >= 0);
    QSRegExpShared *sh = new QSRegExpShared(p, ignoreCase, global); // ### apply flags
    return env()->createShared(this, sh);
}
示例#9
0
void QuickInterpreter::timerEvent(QTimerEvent *e)
{
    int id = e->timerId();
    QSObject function = m_timers[id];

    Q_ASSERT(function.isValid());
    Q_ASSERT(function.isFunction());

    QSList arguments;
    arguments.append(env()->createNumber(id));

    QSObject func_base = QSFuncRefClass::refBase(function);
    QString func_name = QSFuncRefClass::refMember(function).name();

   call(func_base, func_name, arguments);
}
示例#10
0
QSObject QSRectClass::construct(const QSList &args) const
{
  if (args.size() == 1) {
    if (args[ 0 ].objectType() == this) {
      QSObject rt = args.at(0);
      return construct(QRect(*rect(&rt)));
    }
  } else if (args.size() == 4) {
    return construct(QRect(args[ 0 ].toInteger(),
                           args[ 1 ].toInteger(),
                           args[ 2 ].toInteger(),
                           args[ 3 ].toInteger()));
  }

  return construct(QRect());
}
示例#11
0
QSObject QSObjectClass::construct( const QSList &args ) const
{
    if ( args.isEmpty() ) {
	return env()->dynamicClass()->createWritable();
    } else {
	// ### warn about superfluous arguments ?
	return args[0];
    }
}
示例#12
0
QSObject QSPixmapClass::construct( const QSList &args ) const
{
    if ( args.size() > 0 ) {
	QSObject v( args[ 0 ] );
	if ( v.isA( "Pixmap" ) ) {
	    return v;
	} else if ( v.isString() ) {
	    QPixmap pm( v.toString() );
	    return construct( pm );
	}
    }
    return construct( QPixmap() );
}
示例#13
0
QSObject QSPixmapClass::construct( const QSList &args ) const
{
    if ( args.size() > 0 ) {
	QSObject v( args[ 0 ] );
	if ( v.isA( "Pixmap" ) ) {
	    return v;
	} else if ( v.isString() ) {
	    QPixmap pm( v.toString() );
	    return construct( pm );
        } else {
            QVariant var = v.toVariant(QVariant::ByteArray);
            if (var.type() == QVariant::ByteArray) {
                QPixmap pm;
                pm.loadFromData( v.toVariant(QVariant::ByteArray).toByteArray() );
                return construct( pm );
            }
        }
    }
    return construct( QPixmap() );
}
示例#14
0
QSObject QSStringClass::construct( const QSList &args ) const
{
    QString s = args.isEmpty() ? QString::fromLatin1( "" ) : args[0].toString();

    return createString( s );
}
示例#15
0
QSObject QSFuncRefClass::construct( const QSList &args ) const
{
    // ###
  QString p = QString::fromLatin1("");
  QString body;
  int argsSize = args.size();
  if (argsSize == 0) {
    body = "";
  } else if (argsSize == 1) {
    body = args[0].toString();
  } else {
    p = args[0].toString();
    for (int k = 1; k < argsSize - 1; k++)
      p += QString::fromLatin1(",") + args[k].toString();
    body = args[argsSize-1].toString();
  }

  QSLexer::lexer()->setCode( body, -1 );
  if ( qsyyparse() ) {
    /* TODO: free nodes */
    return env()->throwError( SyntaxError, QString::fromLatin1("Syntax error in function body") );
  }

  QSFunctionScopeClass *scope =
      new QSFunctionScopeClass( env()->objectClass() );
  QSFunctionBodyNode * bodyNode = QSProgramNode::last();
  bodyNode->setScopeDefinition( scope );
  scope->setFunctionBodyNode(bodyNode);
  QSMember mem( bodyNode );

  // parse parameter list. throw syntax error on illegal identifiers
  int len = p.length();
  const QChar *c = p.unicode();
  int i = 0, params = 0;
  QString param;
  while (i < len) {
      while (*c == ' ' && i < len)
	  c++, i++;
      if ( QSLexer::isIdentLetter( c->unicode() ) ) {  // else error
	  param = QString(c, 1);
	  c++, i++;
	  while (i < len && ( QSLexer::isIdentLetter( c->unicode() ) ||
			      QSLexer::isDecimalDigit( c->unicode() ) ) ) {
	      param += QString(c, 1);
	      c++, i++;
	  }
	  while (i < len && *c == ' ')
	      c++, i++;
	  if (i == len) {
	      int index = scope->addVariableMember( param, AttributeNone );
	      Q_ASSERT( params==index );
	      params++;
	      break;
	  } else if (*c == ',') {
	      int index = scope->addVariableMember( param, AttributeNone );
	      Q_ASSERT( params==index );
	      params++;
	      c++, i++;
	      continue;
	  } // else error
      }
      return env()->throwError( SyntaxError, QString::fromLatin1("Syntax error in parameter list") );
  }

  scope->setNumArguments( params );
  return createReference( env()->currentScope(), mem );

}
示例#16
0
QSObject QSNumberClass::construct( const QSList &args ) const
{
    double n = args.isEmpty() ? 0.0 : args[0].toNumber();

    return createNumber( n );
}