本文整理汇总了C++中QScriptValueList类的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValueList类的具体用法?C++ QScriptValueList怎么用?C++ QScriptValueList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QScriptValueList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
void Session::processSignIn(const QString &data) {
try {
switch (m_sessionState) {
case SessionClosed:
break;
case SigningIn: {
QScriptValue processSignIn = m_scriptObject.property("processSignIn");
QScriptValueList args;
args.append(data.trimmed());
processSignIn.call(m_scriptObject, args);
break;
}
case SignedIn: {
CommandEvent event(m_player, data);
event.process();
break;
}
}
ScriptEngine *engine = ScriptEngine::instance();
if (engine->hasUncaughtException()) {
LogUtil::logException("Script Exception: %1\n"
"In Session::processSignIn()", engine->uncaughtException());
}
} catch (GameException &exception) {
LogUtil::logError("Exception in Session::processSignIn(): %1", exception.what());
}
}
示例2: Q_D
void QScriptDebuggerScriptedConsoleCommandJob::start()
{
Q_D(QScriptDebuggerScriptedConsoleCommandJob);
QScriptEngine *engine = d->command->globalObject.engine();
engine->setGlobalObject(d->command->globalObject);
QScriptValueList args;
for (int i = 0; i < d->arguments.size(); ++i)
args.append(QScriptValue(engine, d->arguments.at(i)));
QScriptDebuggerConsoleGlobalObject *global;
global = qobject_cast<QScriptDebuggerConsoleGlobalObject*>(engine->globalObject().toQObject());
Q_ASSERT(global != 0);
global->setScheduler(this);
global->setResponseHandler(this);
global->setMessageHandler(d->messageHandler);
global->setConsole(d->console);
d->commandCount = 0;
QScriptValue ret = d->command->execFunction.call(QScriptValue(), args);
global->setScheduler(0);
global->setResponseHandler(0);
global->setMessageHandler(0);
global->setConsole(0);
if (ret.isError()) {
qWarning("*** internal error: %s", qPrintable(ret.toString()));
}
if (d->commandCount == 0)
finish();
}
示例3: locker
QStringList STTwitterText::extractMentions(const QString &text){
QMutexLocker locker(g_processMutex);
QString inText=removeUni6(text).trimmed().normalized(QString::NormalizationForm_C);
QScriptValue caller();
QScriptValueList args;
args.append(inText);
QScriptValue result=g_extractMentionsFunction->call(caller, args);
if(g_engine->hasUncaughtException()){
int line = g_engine->uncaughtExceptionLineNumber();
QByteArray str=g_engine->uncaughtException().toString().toUtf8();
qFatal("Exception while evaluating twttr.txt.extractMentions at line %d: %s", line, str.data());
}
if(result.isUndefined()){
qFatal("Undefined returned by extractMentions");
}
if(!result.isArray()){
qFatal("Non-array object returned by extractMentions");
}
int length=result.property("length").toInteger();
QStringList res;
for(int i=0;i<length;i++){
res<<result.property(i).toString();
}
return res;
}
示例4: setSessionState
void Session::open() {
try {
setSessionState(SigningIn);
ScriptEngine *engine = ScriptEngine::instance();
m_scriptObject = engine->evaluate("new SessionHandler()");
if (engine->hasUncaughtException()) {
LogUtil::logException("Script Exception: %1\n"
"In Session::open()", engine->uncaughtException());
return;
}
QScriptValue setSession = m_scriptObject.property("setSession");
QScriptValueList args;
args.append(engine->toScriptValue(this));
setSession.call(m_scriptObject, args);
if (engine->hasUncaughtException()) {
LogUtil::logException("Script Exception: %1\n"
"In Session::open()", engine->uncaughtException());
}
} catch (GameException &exception) {
LogUtil::logError("Exception in Session::open(): %1", exception.what());
}
}
示例5: Q_ASSERT
QVariant TestClass::extension(Extension extension,
const QVariant &argument)
{
if (extension == Callable) {
Q_ASSERT(m_callableMode != NotCallable);
QScriptContext *ctx = qvariant_cast<QScriptContext*>(argument);
if (m_callableMode == CallableReturnsSum) {
qsreal sum = 0;
for (int i = 0; i < ctx->argumentCount(); ++i)
sum += ctx->argument(i).toNumber();
QScriptValueIterator it(ctx->thisObject());
while (it.hasNext()) {
it.next();
sum += it.value().toNumber();
}
return sum;
} else if (m_callableMode == CallableReturnsArgument) {
return qVariantFromValue(ctx->argument(0));
} else if (m_callableMode == CallableReturnsInvalidVariant) {
return QVariant();
}
} else if (extension == HasInstance) {
Q_ASSERT(m_hasInstance);
QScriptValueList args = qvariant_cast<QScriptValueList>(argument);
Q_ASSERT(args.size() == 2);
QScriptValue obj = args.at(0);
QScriptValue value = args.at(1);
return value.property("foo").equals(obj.property("foo"));
}
return QVariant();
}
示例6: Q_D
/*!
Executes the pending evaluate, if any.
*/
void QScriptDebuggerBackend::doPendingEvaluate(bool postEvent)
{
Q_D(QScriptDebuggerBackend);
QString program = d->pendingEvaluateProgram;
if (program.isEmpty())
return;
int contextIndex = d->pendingEvaluateContextIndex;
QScriptContext *ctx = context(contextIndex);
Q_ASSERT(ctx != 0);
QString fileName = d->pendingEvaluateFileName;
int lineNumber = d->pendingEvaluateLineNumber;
d->pendingEvaluateProgram = QString();
d->pendingEvaluateFileName = QString();
d->pendingEvaluateLineNumber = -1;
d->pendingEvaluateContextIndex = -1;
// push a new context and initialize its scope chain etc.
{
QScriptContext *evalContext = engine()->pushContext();
QScriptValueList scopeChain = ctx->scopeChain();
if (scopeChain.isEmpty())
scopeChain.append(engine()->globalObject());
while (!scopeChain.isEmpty())
evalContext->pushScope(scopeChain.takeLast());
evalContext->setActivationObject(ctx->activationObject());
evalContext->setThisObject(ctx->thisObject());
}
d->agent->enterContinueMode();
// set a flag so that any exception that happens in
// the evaluate() is not sent to the debugger
d->ignoreExceptions = true;
bool hadException = engine()->hasUncaughtException();
QScriptValue ret = engine()->evaluate(program, fileName, lineNumber);
d->ignoreExceptions = false;
if (!hadException && engine()->hasUncaughtException())
engine()->clearExceptions();
engine()->popContext();
QScriptDebuggerValue retret(ret);
QScriptDebuggerEvent e(QScriptDebuggerEvent::InlineEvalFinished);
e.setScriptValue(retret);
if (!ret.isUndefined())
e.setMessage(ret.toString()); // for convenience -- we always need it
e.setNestedEvaluate(engine()->isEvaluating());
if (postEvent) {
QScriptDebuggerEventEvent *de = new QScriptDebuggerEventEvent(e);
d->postEvent(de);
} else {
event(e);
}
}
示例7: GatewayQuery
void SmsGatewayQuery::process(const QString &number)
{
auto engine = m_smsScriptsManager->engine();
auto jsGatewayQueryObject = engine->evaluate("new GatewayQuery()");
auto jsGetGateway = jsGatewayQueryObject.property("getGateway");
QScriptValueList arguments;
arguments.append(number);
arguments.append(engine->newQObject(this));
jsGetGateway.call(jsGatewayQueryObject, arguments);
}
示例8: cls
// Check the overhead of the extension "call"
void tst_QScriptClass::call()
{
QScriptEngine eng;
ExtensionScriptClass cls(&eng);
QScriptValue obj = eng.newObject(&cls);
QScriptValue thisObject;
QScriptValueList args;
args.append(123);
QBENCHMARK {
for (int i = 0; i < iterationNumber; ++i)
(void)obj.call(thisObject, args);
}
}
示例9: foreach
QScriptValue& DerivedNetworkValue::getValue() {
if (!_value.isValid() && _baseValue->isLoaded()) {
RootNetworkValue* root = static_cast<RootNetworkValue*>(_baseValue.data());
ScriptCache* cache = root->getProgram()->getCache();
QScriptValue generator = _baseValue->getValue().property(cache->getGeneratorString());
if (generator.isFunction()) {
QScriptValueList arguments;
foreach (const ParameterInfo& parameter, root->getParameterInfo()) {
arguments.append(cache->getEngine()->newVariant(_parameters.value(parameter.name)));
}
_value = generator.call(QScriptValue(), arguments);
} else {
示例10: argGenerator
// Look up the handler associated with eventName and entityID. If found, evalute the argGenerator thunk and call the handler with those args
void ScriptEngine::generalHandler(const EntityItemID& entityID, const QString& eventName, std::function<QScriptValueList()> argGenerator) {
if (!_registeredHandlers.contains(entityID)) {
return;
}
const RegisteredEventHandlers& handlersOnEntity = _registeredHandlers[entityID];
if (!handlersOnEntity.contains(eventName)) {
return;
}
QScriptValueList handlersForEvent = handlersOnEntity[eventName];
if (!handlersForEvent.isEmpty()) {
QScriptValueList args = argGenerator();
for (int i = 0; i < handlersForEvent.count(); ++i) {
handlersForEvent[i].call(QScriptValue(), args);
}
}
}
示例11: activationObject
/*!
\internal
\since 4.5
Returns the scope chain of this QScriptContext.
*/
QScriptValueList QScriptContext::scopeChain() const
{
activationObject(); //ensure the creation of the normal scope for native context
const JSC::CallFrame *frame = QScriptEnginePrivate::frameForContext(this);
QScriptEnginePrivate *engine = QScript::scriptEngineFromExec(frame);
QScript::APIShim shim(engine);
QScriptValueList result;
JSC::ScopeChainNode *node = frame->scopeChain();
JSC::ScopeChainIterator it(node);
for (it = node->begin(); it != node->end(); ++it) {
JSC::JSObject *object = *it;
if (!object)
continue;
if (object->inherits(&QScript::QScriptActivationObject::info)
&& (static_cast<QScript::QScriptActivationObject*>(object)->delegate() != 0)) {
// Return the object that property access is being delegated to
object = static_cast<QScript::QScriptActivationObject*>(object)->delegate();
}
result.append(engine->scriptValueFromJSCValue(object));
}
return result;
}
示例12: QString
void ScriptableWorker::run()
{
if ( hasLogLevel(LogDebug) ) {
bool isEval = m_args.length() == Arguments::Rest + 2
&& m_args.at(Arguments::Rest) == "eval";
for (int i = Arguments::Rest + (isEval ? 1 : 0); i < m_args.length(); ++i) {
QString indent = isEval ? QString("EVAL:")
: (QString::number(i - Arguments::Rest + 1) + " ");
foreach (const QByteArray &line, m_args.at(i).split('\n')) {
SCRIPT_LOG( indent + getTextData(line) );
indent = " ";
}
}
}
bool hasData;
const quintptr id = m_args.at(Arguments::ActionId).toULongLong(&hasData);
QVariantMap data;
if (hasData)
data = Action::data(id);
const QString currentPath = getTextData(m_args.at(Arguments::CurrentPath));
QScriptEngine engine;
ScriptableProxy proxy(m_wnd, data);
Scriptable scriptable(&proxy);
scriptable.initEngine(&engine, currentPath, data);
if (m_socket) {
QObject::connect( proxy.signaler(), SIGNAL(sendMessage(QByteArray,int)),
m_socket, SLOT(sendMessage(QByteArray,int)) );
QObject::connect( &scriptable, SIGNAL(sendMessage(QByteArray,int)),
m_socket, SLOT(sendMessage(QByteArray,int)) );
QObject::connect( m_socket, SIGNAL(messageReceived(QByteArray,int)),
&scriptable, SLOT(setInput(QByteArray)) );
QObject::connect( m_socket, SIGNAL(disconnected()),
&scriptable, SLOT(abort()) );
QObject::connect( &scriptable, SIGNAL(destroyed()),
m_socket, SLOT(deleteAfterDisconnected()) );
if ( m_socket->isClosed() ) {
SCRIPT_LOG("TERMINATED");
return;
}
m_socket->start();
}
QObject::connect( &scriptable, SIGNAL(requestApplicationQuit()),
qApp, SLOT(quit()) );
QByteArray response;
int exitCode;
if ( m_args.length() <= Arguments::Rest ) {
SCRIPT_LOG("Error: bad command syntax");
exitCode = CommandBadSyntax;
} else {
const QString cmd = getTextData( m_args.at(Arguments::Rest) );
#ifdef HAS_TESTS
if ( cmd == "flush" && m_args.length() == Arguments::Rest + 2 ) {
log( "flush ID: " + getTextData(m_args.at(Arguments::Rest + 1)), LogAlways );
scriptable.sendMessageToClient(QByteArray(), CommandFinished);
return;
}
#endif
QScriptValue fn = engine.globalObject().property(cmd);
if ( !fn.isFunction() ) {
SCRIPT_LOG("Error: unknown command");
const QString msg =
Scriptable::tr("Name \"%1\" doesn't refer to a function.").arg(cmd);
response = createLogMessage(msg, LogError).toUtf8();
exitCode = CommandError;
} else {
/* Special arguments:
* "-" read this argument from stdin
* "--" read all following arguments without control sequences
*/
QScriptValueList fnArgs;
bool readRaw = false;
for ( int i = Arguments::Rest + 1; i < m_args.length(); ++i ) {
const QByteArray &arg = m_args.at(i);
if (!readRaw && arg == "--") {
readRaw = true;
} else {
const QScriptValue value = readRaw || arg != "-"
? scriptable.newByteArray(arg)
: scriptable.input();
fnArgs.append(value);
}
}
engine.evaluate(m_pluginScript);
QScriptValue result = fn.call(QScriptValue(), fnArgs);
//.........这里部分代码省略.........
示例13: switch
//.........这里部分代码省略.........
response.setResult(backend->contextIds()[idx]);
else
response.setError(QScriptDebuggerResponse::InvalidContextIndex);
} break;
case QScriptDebuggerCommand::GetContextInfo: {
QScriptContext *ctx = backend->context(command.contextIndex());
if (ctx)
response.setResult(QScriptContextInfo(ctx));
else
response.setError(QScriptDebuggerResponse::InvalidContextIndex);
} break;
case QScriptDebuggerCommand::GetThisObject: {
QScriptContext *ctx = backend->context(command.contextIndex());
if (ctx)
response.setResult(ctx->thisObject());
else
response.setError(QScriptDebuggerResponse::InvalidContextIndex);
} break;
case QScriptDebuggerCommand::GetActivationObject: {
QScriptContext *ctx = backend->context(command.contextIndex());
if (ctx)
response.setResult(ctx->activationObject());
else
response.setError(QScriptDebuggerResponse::InvalidContextIndex);
} break;
case QScriptDebuggerCommand::GetScopeChain: {
QScriptContext *ctx = backend->context(command.contextIndex());
if (ctx) {
QScriptDebuggerValueList dest;
QScriptValueList src = ctx->scopeChain();
for (int i = 0; i < src.size(); ++i)
dest.append(src.at(i));
response.setResult(dest);
} else {
response.setError(QScriptDebuggerResponse::InvalidContextIndex);
}
} break;
case QScriptDebuggerCommand::ContextsCheckpoint: {
response.setResult(QVariant::fromValue(backend->contextsCheckpoint()));
} break;
case QScriptDebuggerCommand::GetPropertyExpressionValue: {
QScriptContext *ctx = backend->context(command.contextIndex());
int lineNumber = command.lineNumber();
QVariant attr = command.attribute(QScriptDebuggerCommand::UserAttribute);
QStringList path = attr.toStringList();
if (!ctx || path.isEmpty())
break;
QScriptContextInfo ctxInfo(ctx);
if (ctx->callee().isValid()
&& ((lineNumber < ctxInfo.functionStartLineNumber())
|| (lineNumber > ctxInfo.functionEndLineNumber()))) {
break;
}
QScriptValueList objects;
int pathIndex = 0;
if (path.at(0) == QLatin1String("this")) {
objects.append(ctx->thisObject());
++pathIndex;
} else {
objects << ctx->scopeChain();
示例14: MONITOR_LOG
void ScriptableWorker::run()
{
MONITOR_LOG("starting");
QScriptEngine engine;
ScriptableProxy proxy(m_wnd);
Scriptable scriptable(&proxy);
scriptable.initEngine( &engine, QString::fromUtf8(m_args.at(Arguments::CurrentPath)),
m_args.at(Arguments::ActionId) );
if (m_socket) {
QObject::connect( &scriptable, SIGNAL(sendMessage(QByteArray,int)),
m_socket, SLOT(sendMessage(QByteArray,int)) );
QObject::connect( m_socket, SIGNAL(messageReceived(QByteArray,int)),
&scriptable, SLOT(setInput(QByteArray)) );
QObject::connect( m_socket, SIGNAL(disconnected()),
&scriptable, SLOT(abort()) );
QObject::connect( &scriptable, SIGNAL(destroyed()),
m_socket, SLOT(deleteAfterDisconnected()) );
if ( m_socket->isClosed() ) {
MONITOR_LOG("terminated");
return;
}
m_socket->start();
}
QObject::connect( &scriptable, SIGNAL(requestApplicationQuit()),
qApp, SLOT(quit()) );
QByteArray response;
int exitCode;
if ( m_args.length() <= Arguments::Rest ) {
MONITOR_LOG("Error: bad command syntax");
exitCode = CommandBadSyntax;
} else {
const QString cmd = QString::fromUtf8( m_args.at(Arguments::Rest) );
if ( hasLogLevel(LogDebug) ) {
MONITOR_LOG("Client arguments:");
for (int i = Arguments::Rest; i < m_args.length(); ++i)
MONITOR_LOG( " " + QString::fromUtf8(m_args.at(i)) );
}
#ifdef HAS_TESTS
if ( cmd == "flush" && m_args.length() == Arguments::Rest + 2 ) {
MONITOR_LOG( "flush ID: " + QString::fromUtf8(m_args.at(Arguments::Rest + 1)) );
scriptable.sendMessageToClient(QByteArray(), CommandFinished);
return;
}
#endif
QScriptValue fn = engine.globalObject().property(cmd);
if ( !fn.isFunction() ) {
MONITOR_LOG("Error: unknown command");
response = createLogMessage("CopyQ client",
Scriptable::tr("Name \"%1\" doesn't refer to a function.")
.arg(cmd),
LogError).toUtf8();
exitCode = CommandError;
} else {
QScriptValueList fnArgs;
for ( int i = Arguments::Rest + 1; i < m_args.length(); ++i )
fnArgs.append( scriptable.newByteArray(m_args.at(i)) );
QScriptValue result = fn.call(QScriptValue(), fnArgs);
if ( engine.hasUncaughtException() ) {
const QString exceptionText = engine.uncaughtException().toString();
MONITOR_LOG( QString("Error: exception in command \"%1\": %2")
.arg(cmd).arg(exceptionText) );
response = createLogMessage("CopyQ client", exceptionText, LogError).toUtf8();
exitCode = CommandError;
} else {
response = serializeScriptValue(result);
exitCode = CommandFinished;
}
}
}
scriptable.sendMessageToClient(response, exitCode);
MONITOR_LOG("finished");
}
示例15: getZonesByPosition
bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut,
bool& wasChanged, EntityTree::FilterType filterType, EntityItemID& itemID, EntityItemPointer& existingEntity) {
// get the ids of all the zones (plus the global entity edit filter) that the position
// lies within
auto zoneIDs = getZonesByPosition(position);
for (auto id : zoneIDs) {
if (!itemID.isInvalidID() && id == itemID) {
continue;
}
// get the filter pair, etc...
_lock.lockForRead();
FilterData filterData = _filterDataMap.value(id);
_lock.unlock();
if (filterData.valid()) {
if (filterData.rejectAll) {
return false;
}
// check to see if this filter wants to filter this message type
if ((!filterData.wantsToFilterEdit && filterType == EntityTree::FilterType::Edit) ||
(!filterData.wantsToFilterPhysics && filterType == EntityTree::FilterType::Physics) ||
(!filterData.wantsToFilterDelete && filterType == EntityTree::FilterType::Delete) ||
(!filterData.wantsToFilterAdd && filterType == EntityTree::FilterType::Add)) {
wasChanged = false;
return true; // accept the message
}
auto oldProperties = propertiesIn.getDesiredProperties();
auto specifiedProperties = propertiesIn.getChangedProperties();
propertiesIn.setDesiredProperties(specifiedProperties);
QScriptValue inputValues = propertiesIn.copyToScriptValue(filterData.engine, false, true, true);
propertiesIn.setDesiredProperties(oldProperties);
auto in = QJsonValue::fromVariant(inputValues.toVariant()); // grab json copy now, because the inputValues might be side effected by the filter.
QScriptValueList args;
args << inputValues;
args << filterType;
// get the current properties for then entity and include them for the filter call
if (existingEntity && filterData.wantsOriginalProperties) {
auto currentProperties = existingEntity->getProperties(filterData.includedOriginalProperties);
QScriptValue currentValues = currentProperties.copyToScriptValue(filterData.engine, false, true, true);
args << currentValues;
}
// get the zone properties
if (filterData.wantsZoneProperties) {
auto zoneEntity = _tree->findEntityByEntityItemID(id);
if (zoneEntity) {
auto zoneProperties = zoneEntity->getProperties(filterData.includedZoneProperties);
QScriptValue zoneValues = zoneProperties.copyToScriptValue(filterData.engine, false, true, true);
if (filterData.wantsZoneBoundingBox) {
bool success = true;
AABox aaBox = zoneEntity->getAABox(success);
if (success) {
QScriptValue boundingBox = filterData.engine->newObject();
QScriptValue bottomRightNear = vec3ToScriptValue(filterData.engine, aaBox.getCorner());
QScriptValue topFarLeft = vec3ToScriptValue(filterData.engine, aaBox.calcTopFarLeft());
QScriptValue center = vec3ToScriptValue(filterData.engine, aaBox.calcCenter());
QScriptValue boundingBoxDimensions = vec3ToScriptValue(filterData.engine, aaBox.getDimensions());
boundingBox.setProperty("brn", bottomRightNear);
boundingBox.setProperty("tfl", topFarLeft);
boundingBox.setProperty("center", center);
boundingBox.setProperty("dimensions", boundingBoxDimensions);
zoneValues.setProperty("boundingBox", boundingBox);
}
}
// If this is an add or delete, or original properties weren't requested
// there won't be original properties in the args, but zone properties need
// to be the fourth parameter, so we need to pad the args accordingly
int EXPECTED_ARGS = 3;
if (args.length() < EXPECTED_ARGS) {
args << QScriptValue();
}
assert(args.length() == EXPECTED_ARGS); // we MUST have 3 args by now!
args << zoneValues;
}
}
QScriptValue result = filterData.filterFn.call(_nullObjectForFilter, args);
if (filterData.uncaughtExceptions()) {
return false;
}
if (result.isObject()) {
// make propertiesIn reflect the changes, for next filter...
propertiesIn.copyFromScriptValue(result, false);
// and update propertiesOut too. TODO: this could be more efficient...
propertiesOut.copyFromScriptValue(result, false);
// Javascript objects are == only if they are the same object. To compare arbitrary values, we need to use JSON.
//.........这里部分代码省略.........