本文整理汇总了C++中Environment::callFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ Environment::callFunction方法的具体用法?C++ Environment::callFunction怎么用?C++ Environment::callFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment::callFunction方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testEvaluateCallRegFunction
void EnvironmentTestCase::testEvaluateCallRegFunction() {
Environment engine;
engine.registerFunction( "arg", QtScriptFunctions::arg );
ASSERT_EQUAL( engine.callFunction( "arg" ).isUndefined(), true );
ASSERT_EQUAL( engine.callFunction( "arg", 5 ).toNumber(), 5 );
ASSERT_EXCEPTION( engine.callFunction( "arg", 5, engine.newArray() ), ScriptException );
};
示例2: testRegisterStaticMethods
void RegistrationClassTestCase::testRegisterStaticMethods() {
Environment engine;
QSharedPointer<RegistrationClass> f( RegistrationClass::newClass<QtScriptObject>() );
f->getStaticFunctions().push_back( RegistrationFunction( "arg", QtScriptFunctions::arg ) );
f->registerObject( engine.globalObject(), &engine );
ASSERT_EQUAL( engine.callFunction( engine.globalObject().property( "QtScriptObject" ), "arg", 5 ).toInt32(), 5 );
};
示例3: testRegisterExtendStaticMethods
void RegistrationClassTestCase::testRegisterExtendStaticMethods() {
Environment engine;
RegistrationClass f( "String" );
f.getStaticFunctions().push_back( RegistrationFunction( "arg", QtScriptFunctions::arg ) );
f.registerObject( engine.globalObject(), &engine );
ASSERT_EQUAL( engine.callFunction( engine.globalObject().property( "String" ), "arg", 5 ).toInt32(), 5 );
};
示例4: testRegisterExtendDynamicMethods
void RegistrationClassTestCase::testRegisterExtendDynamicMethods() {
Environment engine;
RegistrationClass f( "String" );
f.getDynamicFunctions().push_back( RegistrationFunction( "arg", QtScriptFunctions::arg ) );
f.registerObject( engine.globalObject(), &engine );
QScriptValue v = engine.evaluate( "new String();" );
ASSERT_REQUIRE_EQUAL( v.isObject(), true );
ASSERT_EQUAL( engine.callFunction( v, "arg", 5 ).toInt32(), 5 );
};
示例5: testRegisterDynamicMethods
void RegistrationClassTestCase::testRegisterDynamicMethods() {
Environment engine;
QSharedPointer<RegistrationClass> f( RegistrationClass::newClass<QtScriptObject>() );
f->getDynamicFunctions().push_back( RegistrationFunction( "arg", QtScriptFunctions::arg ) );
f->registerObject( engine.globalObject(), &engine );
QScriptValue v = engine.evaluate( "new QtScriptObject();" );
ASSERT_REQUIRE_EQUAL( v.isObject(), true );
ASSERT_EQUAL( engine.callFunction( v, "arg", 5 ).toInt32(), 5 );
};
示例6: testEvaluateCallScriptFunction
void EnvironmentTestCase::testEvaluateCallScriptFunction() {
Environment engine;
QString script = "function fun() { return arguments.length; }";
ASSERT_EQUAL( engine.evaluate( script ).isValid(), true );
ASSERT_EQUAL( engine.callFunction( "fun" ).toInteger(), 0 );
ASSERT_EQUAL( engine.callFunction( "fun", 1 ).toInteger(), 1 );
ASSERT_EQUAL( engine.callFunction( "fun", 1, 2 ).toInteger(), 2 );
ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3 ).toInteger(), 3 );
ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4 ).toInteger(), 4 );
ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5 ).toInteger(), 5 );
ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5, 6 ).toInteger(), 6 );
ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5, 6, 7 ).toInteger(), 7 );
ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5, 6, 7, 8 ).toInteger(), 8 );
ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5, 6, 7, 8, 9 ).toInteger(), 9 );
ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ).toInteger(), 10 );
};