void REcmaSharedPointerRay::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RRayPointer*) 0))); protoCreated = true; } // primary base class RXLine: proto->setPrototype(engine.defaultPrototype( qMetaTypeId<RXLinePointer>())); /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // copy: REcmaHelper::registerFunction(&engine, proto, copy, "copy"); // shared pointer support: REcmaHelper::registerFunction(&engine, proto, data, "data"); REcmaHelper::registerFunction(&engine, proto, isNull, "isNull"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class RXLine REcmaHelper::registerFunction(&engine, proto, getRXLine, "getRXLine"); // conversion for base class RShape REcmaHelper::registerFunction(&engine, proto, getRShape, "getRShape"); // conversion for base class RDirected REcmaHelper::registerFunction(&engine, proto, getRDirected, "getRDirected"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, clone, "clone"); REcmaHelper::registerFunction(&engine, proto, trimEndPoint, "trimEndPoint"); REcmaHelper::registerFunction(&engine, proto, getPointsWithDistanceToEnd, "getPointsWithDistanceToEnd"); REcmaHelper::registerFunction(&engine, proto, reverse, "reverse"); REcmaHelper::registerFunction(&engine, proto, getClippedLine, "getClippedLine"); REcmaHelper::registerFunction(&engine, proto, getVectorTo, "getVectorTo"); REcmaHelper::registerFunction(&engine, proto, stretch, "stretch"); engine.setDefaultPrototype( qMetaTypeId<RRayPointer>(), *proto); QScriptValue ctor = engine.newFunction(createEcma, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RRayPointer", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
// includes for base ecma wrapper classes void REcmaPenListener::init(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL) { proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RPenListener*) 0))); protoCreated = true; } QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, updatePen, "updatePen"); REcmaHelper::registerFunction(&engine, proto, clearPen, "clearPen"); engine.setDefaultPrototype( qMetaTypeId<RPenListener*>(), *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RPenListener", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ) { delete proto; } }
bool testPlayerScript(QString path, int player, int difficulty) { QScriptEngine *engine = new QScriptEngine(); QFile input(path); input.open(QIODevice::ReadOnly); QString source(QString::fromUtf8(input.readAll())); input.close(); // Special functions engine->globalObject().setProperty("setTimer", engine->newFunction(js_setTimer)); engine->globalObject().setProperty("queue", engine->newFunction(js_queue)); engine->globalObject().setProperty("removeTimer", engine->newFunction(js_removeTimer)); engine->globalObject().setProperty("include", engine->newFunction(js_include)); engine->globalObject().setProperty("bind", engine->newFunction(js_bind)); // Special global variables engine->globalObject().setProperty("version", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("selectedPlayer", 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("gameTime", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("difficulty", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("mapName", "TEST", QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("baseType", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("alliancesType", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("powerType", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("maxPlayers", CUR_PLAYERS, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("scavengers", true, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("mapWidth", 80, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("mapHeight", 80, QScriptValue::ReadOnly | QScriptValue::Undeletable); // Most special global engine->globalObject().setProperty("me", player, QScriptValue::ReadOnly | QScriptValue::Undeletable); // Register functions to the script engine here engine->globalObject().setProperty("_", engine->newFunction(js_translate)); engine->globalObject().setProperty("label", engine->newFunction(js_label)); engine->globalObject().setProperty("enumLabels", engine->newFunction(js_enumLabels)); engine->globalObject().setProperty("enumGateways", engine->newFunction(js_enumGateways)); // horrible hacks follow -- do not rely on these being present! engine->globalObject().setProperty("hackNetOff", engine->newFunction(js_hackNetOff)); engine->globalObject().setProperty("hackNetOn", engine->newFunction(js_hackNetOn)); engine->globalObject().setProperty("objFromId", engine->newFunction(js_objFromId)); // General functions -- geared for use in AI scripts engine->globalObject().setProperty("debug", engine->newFunction(js_debug)); engine->globalObject().setProperty("console", engine->newFunction(js_console)); engine->globalObject().setProperty("structureIdle", engine->newFunction(js_structureIdle)); engine->globalObject().setProperty("enumStruct", engine->newFunction(js_enumStruct)); engine->globalObject().setProperty("enumStructOffWorld", engine->newFunction(js_enumStructOffWorld)); engine->globalObject().setProperty("enumDroid", engine->newFunction(js_enumDroid)); engine->globalObject().setProperty("enumGroup", engine->newFunction(js_enumGroup)); engine->globalObject().setProperty("enumFeature", engine->newFunction(js_enumFeature)); engine->globalObject().setProperty("enumBlips", engine->newFunction(js_enumBlips)); engine->globalObject().setProperty("enumResearch", engine->newFunction(js_enumResearch)); engine->globalObject().setProperty("getResearch", engine->newFunction(js_getResearch)); engine->globalObject().setProperty("pursueResearch", engine->newFunction(js_pursueResearch)); engine->globalObject().setProperty("distBetweenTwoPoints", engine->newFunction(js_distBetweenTwoPoints)); engine->globalObject().setProperty("newGroup", engine->newFunction(js_newGroup)); engine->globalObject().setProperty("groupAddArea", engine->newFunction(js_groupAddArea)); engine->globalObject().setProperty("groupAddDroid", engine->newFunction(js_groupAddDroid)); engine->globalObject().setProperty("groupSize", engine->newFunction(js_groupSize)); engine->globalObject().setProperty("orderDroidLoc", engine->newFunction(js_orderDroidLoc)); engine->globalObject().setProperty("playerPower", engine->newFunction(js_playerPower)); engine->globalObject().setProperty("isStructureAvailable", engine->newFunction(js_isStructureAvailable)); engine->globalObject().setProperty("pickStructLocation", engine->newFunction(js_pickStructLocation)); engine->globalObject().setProperty("droidCanReach", engine->newFunction(js_droidCanReach)); engine->globalObject().setProperty("orderDroidStatsLoc", engine->newFunction(js_orderDroidBuild)); // deprecated engine->globalObject().setProperty("orderDroidBuild", engine->newFunction(js_orderDroidBuild)); engine->globalObject().setProperty("orderDroidObj", engine->newFunction(js_orderDroidObj)); engine->globalObject().setProperty("orderDroid", engine->newFunction(js_orderDroid)); engine->globalObject().setProperty("buildDroid", engine->newFunction(js_buildDroid)); engine->globalObject().setProperty("addDroid", engine->newFunction(js_addDroid)); engine->globalObject().setProperty("addFeature", engine->newFunction(js_addFeature)); engine->globalObject().setProperty("componentAvailable", engine->newFunction(js_componentAvailable)); engine->globalObject().setProperty("isVTOL", engine->newFunction(js_isVTOL)); engine->globalObject().setProperty("safeDest", engine->newFunction(js_safeDest)); engine->globalObject().setProperty("activateStructure", engine->newFunction(js_activateStructure)); engine->globalObject().setProperty("chat", engine->newFunction(js_chat)); // Functions that operate on the current player only engine->globalObject().setProperty("centreView", engine->newFunction(js_centreView)); engine->globalObject().setProperty("playSound", engine->newFunction(js_playSound)); engine->globalObject().setProperty("gameOverMessage", engine->newFunction(js_gameOverMessage)); // Global state manipulation -- not for use with skirmish AI (unless you want it to cheat, obviously) engine->globalObject().setProperty("setStructureLimits", engine->newFunction(js_setStructureLimits)); engine->globalObject().setProperty("applyLimitSet", engine->newFunction(js_applyLimitSet)); engine->globalObject().setProperty("setMissionTime", engine->newFunction(js_setMissionTime)); engine->globalObject().setProperty("setReinforcementTime", engine->newFunction(js_setReinforcementTime)); engine->globalObject().setProperty("completeResearch", engine->newFunction(js_completeResearch)); engine->globalObject().setProperty("enableResearch", engine->newFunction(js_enableResearch)); engine->globalObject().setProperty("setPower", engine->newFunction(js_setPower)); engine->globalObject().setProperty("setTutorialMode", engine->newFunction(js_setTutorialMode)); engine->globalObject().setProperty("setDesign", engine->newFunction(js_setDesign)); engine->globalObject().setProperty("setMiniMap", engine->newFunction(js_setMiniMap)); engine->globalObject().setProperty("addReticuleButton", engine->newFunction(js_addReticuleButton)); engine->globalObject().setProperty("removeReticuleButton", engine->newFunction(js_removeReticuleButton)); engine->globalObject().setProperty("enableStructure", engine->newFunction(js_enableStructure)); engine->globalObject().setProperty("makeComponentAvailable", engine->newFunction(js_makeComponentAvailable)); engine->globalObject().setProperty("enableComponent", engine->newFunction(js_enableComponent)); engine->globalObject().setProperty("enableTemplate", engine->newFunction(js_enableTemplate)); engine->globalObject().setProperty("allianceExistsBetween", engine->newFunction(js_allianceExistsBetween)); engine->globalObject().setProperty("removeStruct", engine->newFunction(js_removeStruct)); engine->globalObject().setProperty("removeObject", engine->newFunction(js_removeObject)); engine->globalObject().setProperty("setScrollParams", engine->newFunction(js_setScrollParams)); engine->globalObject().setProperty("addStructure", engine->newFunction(js_addStructure)); engine->globalObject().setProperty("loadLevel", engine->newFunction(js_loadLevel)); engine->globalObject().setProperty("setDroidExperience", engine->newFunction(js_setDroidExperience)); engine->globalObject().setProperty("setNoGoArea", engine->newFunction(js_setNoGoArea)); engine->globalObject().setProperty("setAlliance", engine->newFunction(js_setAlliance)); engine->globalObject().setProperty("setAssemblyPoint", engine->newFunction(js_setAssemblyPoint)); // Set some useful constants engine->globalObject().setProperty("DORDER_ATTACK", 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_MOVE", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_SCOUT", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_BUILD", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_HELPBUILD", 3, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_LINEBUILD", 4, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_REPAIR", 5, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_RETREAT", 6, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_PATROL", 7, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_DEMOLISH", 8, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_EMBARK", 9, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_DISEMBARK", 10, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_FIRESUPPORT", 11, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_HOLD", 12, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_RTR", 13, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_RTB", 14, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_STOP", 15, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DORDER_REARM", 16, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("COMMAND", 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("BUILD", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("MANUFACTURE", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("RESEARCH", 3, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("INTELMAP", 4, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DESIGN", 5, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("CANCEL", 6, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("CAMP_CLEAN", 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("CAMP_BASE", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("CAMP_WALLS", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("NO_ALLIANCES", 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("ALLIANCES", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("ALLIANCES_TEAMS", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("BEING_BUILT", SS_BEING_BUILT, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("BUILT", SS_BUILT, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("BEING_DEMOLISHED", SS_BEING_DEMOLISHED, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DROID_CONSTRUCT", 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DROID_WEAPON", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DROID_PERSON", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DROID_REPAIR", 3, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DROID_SENSOR", 4, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DROID_ECM", 5, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DROID_CYBORG", 6, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DROID_TRANSPORTER", 7, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DROID_COMMAND", 8, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("HQ", 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("FACTORY", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("POWER_GEN", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("RESOURCE_EXTRACTOR", 3, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DEFENSE", 4, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("LASSAT", 5, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("WALL", 6, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("RESEARCH_LAB", 7, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("REPAIR_FACILITY", 8, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("CYBORG_FACTORY", 9, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("VTOL_FACTORY", 10, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("REARM_PAD", 11, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("SAT_UPLINK", 12, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("GATE", 13, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("COMMAND_CONTROL", 14, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("EASY", 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("MEDIUM", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("HARD", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("INSANE", 3, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("STRUCTURE", OBJ_STRUCTURE, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("DROID", OBJ_DROID, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("FEATURE", OBJ_FEATURE, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("POSITION", POSITION, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("AREA", AREA, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("ALL_PLAYERS", -1, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("ALLIES", -2, QScriptValue::ReadOnly | QScriptValue::Undeletable); QScriptValue playerData = engine->newArray(CUR_PLAYERS); for (int i = 0; i < CUR_PLAYERS; i++) { QScriptValue vector = engine->newObject(); vector.setProperty("difficulty", 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); vector.setProperty("colour", 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); vector.setProperty("position", i, QScriptValue::ReadOnly | QScriptValue::Undeletable); vector.setProperty("team", i, QScriptValue::ReadOnly | QScriptValue::Undeletable); vector.setProperty("isAI", i != 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); vector.setProperty("isHuman", i == 0, QScriptValue::ReadOnly | QScriptValue::Undeletable); playerData.setProperty(i, vector, QScriptValue::ReadOnly | QScriptValue::Undeletable); } engine->globalObject().setProperty("playerData", playerData, QScriptValue::ReadOnly | QScriptValue::Undeletable); // Static map knowledge about start positions //== \item[derrickPositions] An array of derrick starting positions on the current map. Each item in the array is an //== object containing the x and y variables for a derrick. //== \item[startPositions] An array of player start positions on the current map. Each item in the array is an //== object containing the x and y variables for a player start position. QScriptValue startPositions = engine->newArray(CUR_PLAYERS); for (int i = 0; i < CUR_PLAYERS; i++) { QScriptValue vector = engine->newObject(); vector.setProperty("x", 40, QScriptValue::ReadOnly | QScriptValue::Undeletable); vector.setProperty("y", 40, QScriptValue::ReadOnly | QScriptValue::Undeletable); startPositions.setProperty(i, vector, QScriptValue::ReadOnly | QScriptValue::Undeletable); } QScriptValue derrickPositions = engine->newArray(6); for (int i = 0; i < 6; i++) { QScriptValue vector = engine->newObject(); vector.setProperty("x", 40, QScriptValue::ReadOnly | QScriptValue::Undeletable); vector.setProperty("y", 40, QScriptValue::ReadOnly | QScriptValue::Undeletable); derrickPositions.setProperty(i, vector, QScriptValue::ReadOnly | QScriptValue::Undeletable); } engine->globalObject().setProperty("derrickPositions", derrickPositions, QScriptValue::ReadOnly | QScriptValue::Undeletable); engine->globalObject().setProperty("startPositions", startPositions, QScriptValue::ReadOnly | QScriptValue::Undeletable); QScriptSyntaxCheckResult syntax = QScriptEngine::checkSyntax(source); if (syntax.state() != QScriptSyntaxCheckResult::Valid) { qFatal("Syntax error in %s line %d: %s", path.toUtf8().constData(), syntax.errorLineNumber(), syntax.errorMessage().toUtf8().constData()); return false; } QScriptValue result = engine->evaluate(source, path); if (engine->hasUncaughtException()) { int line = engine->uncaughtExceptionLineNumber(); qFatal("Uncaught exception at line %d, file %s: %s", line, path.toUtf8().constData(), result.toString().toUtf8().constData()); return false; } // Call init callFunction(engine, "eventGameInit", QScriptValueList()); // Now set gameTime to something proper engine->globalObject().setProperty("gameTime", 10101, QScriptValue::ReadOnly | QScriptValue::Undeletable); callFunction(engine, "eventStartLevel", QScriptValueList()); callFunction(engine, "eventLaunchTransporter", QScriptValueList()); callFunction(engine, "eventReinforcementsArrived", QScriptValueList()); callFunction(engine, "eventMissionTimeout", QScriptValueList()); callFunction(engine, "eventVideoDone", QScriptValueList()); // Call other events { QScriptValueList args; args += convDroid(engine); args += convStructure(engine); callFunction(engine, "eventDroidBuilt", args); } { QScriptValueList args; args += convStructure(engine); args += convObj(engine); callFunction(engine, "eventStructureAttacked", args); } { QScriptValueList args; args += convResearch(engine); args += convStructure(engine); callFunction(engine, "eventResearched", args); } { QScriptValueList args; args += convObj(engine); args += convObj(engine); callFunction(engine, "eventAttacked", args); } { QScriptValueList args; args += convStructure(engine); args += convDroid(engine); callFunction(engine, "eventStructureBuilt", args); } { QScriptValueList args; args += convDroid(engine); callFunction(engine, "eventDroidIdle", args); } { QScriptValueList args; args += QScriptValue(0); args += QScriptValue(1); args += QScriptValue("message"); callFunction(engine, "eventChat", args); } { QScriptValueList args; args += convObj(engine); args += convObj(engine); callFunction(engine, "eventObjectSeen", args); } // Now test timers // TODO -- implement object parameters for (int i = 0; i < timers.size(); ++i) { timerNode node = timers.at(i); callFunction(node.engine, node.function, QScriptValueList(), true); } // Clean up delete engine; timers.clear(); return true; }
int main(int argc, char *argv[]) { QApplication *app; if (argc >= 2 && !qstrcmp(argv[1], "-tty")) { ++argv; --argc; app = new QApplication(argc, argv, QApplication::Tty); } else { app = new QApplication(argc, argv); } QScriptEngine *eng = new QScriptEngine(); QScriptValue globalObject = eng->globalObject(); globalObject.setProperty("load", eng->newFunction(loadScripts, /*length=*/1)); { if (!globalObject.property("qt").isObject()) globalObject.setProperty("qt", eng->newObject()); QScriptValue qscript = eng->newObject(); qscript.setProperty("importExtension", eng->newFunction(importExtension)); globalObject.property("qt").setProperty("script", qscript); } ByteArrayClass *byteArrayClass = new ByteArrayClass(eng); globalObject.setProperty("ByteArray", byteArrayClass->constructor()); if (! *++argv) { interactive(eng); return EXIT_SUCCESS; } while (const char *arg = *argv++) { QString fn = QString::fromLocal8Bit(arg); if (fn == QLatin1String("-i")) { interactive(eng); break; } QString contents; int lineNumber = 1; if (fn == QLatin1String("-")) { QTextStream stream(stdin, QFile::ReadOnly); contents = stream.readAll(); } else { QFile file(fn); if (file.open(QFile::ReadOnly)) { QTextStream stream(&file); contents = stream.readAll(); file.close(); // strip off #!/usr/bin/env qscript line if (contents.startsWith("#!")) { contents.remove(0, contents.indexOf("\n")); ++lineNumber; } } } if (contents.isEmpty()) continue; QScriptValue r = eng->evaluate(contents, fn, lineNumber); if (eng->hasUncaughtException()) { QStringList backtrace = eng->uncaughtExceptionBacktrace(); fprintf (stderr, " %s\n%s\n\n", qPrintable(r.toString()), qPrintable(backtrace.join("\n"))); return EXIT_FAILURE; } } delete eng; delete app; return EXIT_SUCCESS; }
void REcmaDimRotatedData::init(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RDimRotatedData*) 0))); protoCreated = true; } // primary base class RDimLinearData: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<RDimLinearData*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class RDimLinearData REcmaHelper::registerFunction(&engine, proto, getRDimLinearData, "getRDimLinearData"); // conversion for base class RDimensionData REcmaHelper::registerFunction(&engine, proto, getRDimensionData, "getRDimensionData"); // conversion for base class REntityData REcmaHelper::registerFunction(&engine, proto, getREntityData, "getREntityData"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, isValid, "isValid"); REcmaHelper::registerFunction(&engine, proto, setRotation, "setRotation"); REcmaHelper::registerFunction(&engine, proto, getRotation, "getRotation"); REcmaHelper::registerFunction(&engine, proto, getReferencePoints, "getReferencePoints"); REcmaHelper::registerFunction(&engine, proto, rotate, "rotate"); REcmaHelper::registerFunction(&engine, proto, mirror, "mirror"); REcmaHelper::registerFunction(&engine, proto, getShapes, "getShapes"); REcmaHelper::registerFunction(&engine, proto, getMeasuredValue, "getMeasuredValue"); REcmaHelper::registerFunction(&engine, proto, getAutoLabel, "getAutoLabel"); engine.setDefaultPrototype( qMetaTypeId<RDimRotatedData*>(), *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RDimRotatedData", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
bool DSO::addCustomFile(const QString &fileName) { m_lastCustomError = ""; SkFile file(fileName); if (!file.open(SkFile::ReadOnly | SkFile::Text)) { m_lastCustomError = tr("File not found!"); return false; } QString code; do { if (file.atEnd()) { break; } QString line = file.readLine(); if (line.simplified() == "*DATA") { break; } code += line; } while (true); QScriptEngine engine; scriptNewTypes.clear(); engine.globalObject().setProperty("AUTHOR", ""); engine.globalObject().setProperty("EPOCH", 2000); engine.globalObject().setProperty("DESCRIPTION", ""); engine.globalObject().setProperty("POINT_SOURCE", 0); engine.globalObject().setProperty("CIRCLE", 1); engine.globalObject().setProperty("CROSS", 2); engine.globalObject().setProperty("RECTANGLE", 3); QScriptValue fun = engine.newFunction(DEFINE_CUSTOM_OBJECT, 3); engine.globalObject().setProperty("DEFINE_CUSTOM_OBJECT", fun); QScriptValue result = engine.evaluate(code); if (engine.hasUncaughtException()) { int line = engine.uncaughtExceptionLineNumber(); m_lastCustomError = QString("uncaught exception at line ") + line + " : " + result.toString(); return false; } QString author; QString description; double epoch; int nameOffset = 0; // TODO: dat globalne QScriptValueIterator it(engine.globalObject()); while (it.hasNext()) { it.next(); if (it.name() == "AUTHOR") { author = it.value().toString(); } else if (it.name() == "DESCRIPTION") { description = it.value().toString(); } else if (it.name() == "EPOCH") { epoch = it.value().toNumber(); } } do { if (file.atEnd()) { break; } QString line = file.readLine().simplified(); if (line.startsWith("//")) { continue; } if (line.size() == 0) { continue; } QStringList list = line.split("|"); //qDebug() << line << list.count(); if (list.count() != 10) { m_lastCustomError = "Invalid record"; return false; } QString type = list[0].simplified(); QString name1 = list[1].simplified(); QString name2 = list[2].simplified(); double ra = parseRA(list[3]); double dec = parseDec(list[4]); double sizeA = parseSize(list[5]); double sizeB = parseSize(list[6]); double mag = list[7].simplified().toDouble(); double pa = list[8].simplified().toDouble(); QString cls = list[9].simplified(); dso_t dso; if (qIsNaN(ra) || qIsNaN(dec)) { m_lastCustomError = "Invalid RA/Dec value"; return false; } m_namesMap[USER_OFFSET + nameOffset].append(name1); m_namesMap[USER_OFFSET + nameOffset].append(name2); nameOffset++; dso.cataloque = 0; // TODO: dodelat dso.galType = 0; // TODO: dodelat dso.mag = SkMath::isNear(mag, 0) ? NO_DSO_MAG : (short)(mag * 100.); dso.nameOffs = USER_OFFSET + nameOffset; dso.pa = pa; //TODO: bez PA dso.rd.ra = SkMath::toRad(ra); dso.rd.dec = SkMath::toRad(dec); //TODO:epoch dso.shape = NO_DSO_SHAPE; dso.sx = sizeA; dso.sy = sizeB; dso.type = DSOT_CUSTOM_FLAG; // TODO: user types qDebug() << line; qDebug() << type << name1 << name2 << ra << dec << sizeA << sizeB << mag << pa << cls; } while (true); return true; }
void TextImportDialog::doImport() { // Get settings from UI QString fileName; QString pastedTempfile; if(m_ui->tabWidget->currentIndex() == 1) { // copy/paste buffer QString text = m_ui->plainTextEdit->toPlainText(); pastedTempfile = tr("%1/dviz-textimportdialog-pasted.txt").arg(QDir::tempPath()); QFile file(pastedTempfile); if(!file.open(QIODevice::WriteOnly)) { QMessageBox::critical(this,tr("Can't Wriite Temp File"),QString(tr("Unable to write temp file %1")).arg(pastedTempfile)); return; } QTextStream stream(&file); stream << text; file.close(); fileName = pastedTempfile; qDebug() << "Wrote temp file: "<<pastedTempfile; } else { fileName = m_ui->filename->text(); AppSettings::setPreviousPath("textimport",fileName); } // Store the originally-given file for the group name later QString originalFileName = fileName; bool isPlainText = m_ui->fmtPlain->isChecked(); QSettings().setValue("textimport/plaintext",isPlainText); QString scriptFilename = m_ui->scriptFile->text(); AppSettings::setPreviousPath("script",scriptFilename); QString preprocFilename = m_ui->preprocFile->text(); AppSettings::setPreviousPath("preproc",preprocFilename); // Setup progress dialog QProgressDialog progress(QString(tr("Loading %1...")).arg(fileName),"",0,0); progress.setWindowModality(Qt::WindowModal); progress.setCancelButton(0); // hide cancel button progress.setWindowIcon(QIcon(":/data/icon-d.png")); progress.setWindowTitle(QString(tr("Loading %1")).arg(fileName)); progress.show(); m_progress = &progress; QApplication::processEvents(); qDebug() << "TextImportDialog::doImport(): Start, file:"<<fileName<<", isPLain? "<<isPlainText<<", script:"<<scriptFilename<<", preproc:"<<preprocFilename; QString tempFilename; if(!preprocFilename.isEmpty()) { tempFilename = tr("%1/dviz-textimportdialog-temp.txt").arg(QDir::tempPath()); QProcess proc; proc.start(preprocFilename, QStringList() << fileName << tempFilename); bool result = proc.waitForFinished(); if(!result) { QMessageBox::critical(this,tr("Pre-Processor Problem"),QString(tr("Preproc %1 didn't finish properly. Check the console - not sure why.")).arg(fileName)); return; } fileName = tempFilename; qDebug() << "TextImportDialog::doImport(): Preprocessor completed, using preproc temp file: "<<tempFilename; } // Load text file QFile file(fileName); if(!file.open(QIODevice::ReadOnly)) { QMessageBox::critical(this,tr("Can't Read File"),QString(tr("Unable to open %1")).arg(fileName)); return; } QTextStream stream(&file); QString fileContents = stream.readAll(); if(!tempFilename.isEmpty()) file.remove(); // file is closed before it is removed // Remove the paste buffer //if(!pastedTempfile.isEmpty()) // QFile(pastedTempfile).remove(); // Load script file QScriptEngine scriptEngine; if(!scriptFilename.isEmpty()) { // For debug output static_currentScriptFile = scriptFilename; // Install some custom functions for the script QScriptValue fDebug = scriptEngine.newFunction(TextImportDialog_script_qDebug); QScriptValue fFindTextItem = scriptEngine.newFunction(TextImportDialog_script_findTextItem); QScriptValue fChangeFntSz = scriptEngine.newFunction(TextImportDialog_script_changeFontSize); QScriptValue fFindFntSz = scriptEngine.newFunction(TextImportDialog_script_findFontSize); QScriptValue fCntrTextBox = scriptEngine.newFunction(TextImportDialog_script_intelligentCenterTextbox); QScriptValue fFileList = scriptEngine.newFunction(TextImportDialog_script_getFileList); QScriptValue fChangeBg = scriptEngine.newFunction(TextImportDialog_script_changeSlideBackground); QScriptValue fGuessTimeout = scriptEngine.newFunction(TextImportDialog_script_guessSlideTimeout); scriptEngine.globalObject().setProperty("debug", fDebug); scriptEngine.globalObject().setProperty("findTextItem", fFindTextItem); scriptEngine.globalObject().setProperty("changeFontSize", fChangeFntSz); scriptEngine.globalObject().setProperty("findFontSize", fFindFntSz); scriptEngine.globalObject().setProperty("intelligentCenterTextbox", fCntrTextBox); scriptEngine.globalObject().setProperty("getFileList", fFileList); scriptEngine.globalObject().setProperty("changeSlideBackground", fChangeBg); scriptEngine.globalObject().setProperty("guessSlideTimeout", fGuessTimeout); scriptEngine.globalObject().setProperty("InPrimaryGroup", true); QScriptValue scriptBibleBrowser = scriptEngine.newQObject(MainWindow::mw()->bibleBrowser()); scriptEngine.globalObject().setProperty("BibleBrowser", scriptBibleBrowser); // Read the file QFile scriptFile(scriptFilename); if(!scriptFile.open(QIODevice::ReadOnly)) { QMessageBox::critical(this,tr("Can't Read Script"),QString(tr("Unable to open script %1")).arg(fileName)); return; } // Evaulate the contents of the file QTextStream stream(&scriptFile); QString contents = stream.readAll(); scriptFile.close(); QScriptValue scriptResult = scriptEngine.evaluate(contents, fileName); // Alert user of syntax error in script if (scriptEngine.hasUncaughtException()) { int line = scriptEngine.uncaughtExceptionLineNumber(); //qDebug() << "uncaught exception at line" << line << ":" << result.toString(); QMessageBox::critical(this,tr("Script Exception"),QString(tr("Uncaught Exception in file %1, line %2: \n\t%3\n\nImport canceled. Please fix script and try again.")) .arg(scriptFilename) .arg(line) .arg(scriptResult.toString())); return; } } // Generate the slides and set the group title qDebug() << "TextImportDialog::doImport(): Creating template and slides for primary group"; SlideGroup *templateGroup = getTemplate(); SlideGroup *group = generateSlideGroup(templateGroup, fileContents, isPlainText, scriptEngine, scriptFilename); if(!group) { // script error or other error, cancel import return; } // Apply group title using the original file name, just in case we used a pre-processor if(group->groupTitle().isEmpty()) group->setGroupTitle(AbstractItem::guessTitle(QFileInfo(originalFileName).baseName())); qDebug() << "TextImportDialog::doImport(): Checking for alternate groups"; // Set a flag so scripts can respond differently for alternate groups if(!scriptFilename.isEmpty()) scriptEngine.globalObject().setProperty("InPrimaryGroup", false); // Create alternate groups for outputs if present in template QList<Output*> allOut = AppSettings::outputs(); foreach(Output *out, allOut) { SlideGroup *outputTemplate = templateGroup->altGroupForOutput(out); if(outputTemplate) { SlideGroup *existingAlt = group->altGroupForOutput(out); qDebug() << "TextImportDialog::doImport(): [prep] Creating alternate group from template for output: "<<out->name()<<", existingAlt: "<<existingAlt; SlideGroup *altGroup = generateSlideGroup(outputTemplate, fileContents, isPlainText, scriptEngine, scriptFilename, existingAlt, group); if(!altGroup) { // script error or other error, cancel import delete group; return; } altGroup->setGroupTitle(tr("Alternate %1 for %2").arg(group->groupTitle()).arg(out->name())); group->setAltGroupForOutput(out, altGroup); } }
void QHistogram::Register(QScriptEngine& engine) { QScriptValue ctor = engine.newFunction(QHistogram::New); QScriptValue metaObject = engine.newQMetaObject(&QHistogram::staticMetaObject, ctor); engine.globalObject().setProperty("Histogram", metaObject); }
void REcmaSpatialIndexNavel::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RSpatialIndexNavel*) 0))); protoCreated = true; } // primary base class RSpatialIndex: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<RSpatialIndex*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class RSpatialIndex REcmaHelper::registerFunction(&engine, proto, getRSpatialIndex, "getRSpatialIndex"); // conversion for base class RRequireHeap REcmaHelper::registerFunction(&engine, proto, getRRequireHeap, "getRRequireHeap"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, clear, "clear"); REcmaHelper::registerFunction(&engine, proto, bulkLoad, "bulkLoad"); REcmaHelper::registerFunction(&engine, proto, addToIndex, "addToIndex"); REcmaHelper::registerFunction(&engine, proto, removeFromIndex, "removeFromIndex"); REcmaHelper::registerFunction(&engine, proto, queryIntersected, "queryIntersected"); REcmaHelper::registerFunction(&engine, proto, queryIntersectedSimple, "queryIntersectedSimple"); REcmaHelper::registerFunction(&engine, proto, queryContained, "queryContained"); REcmaHelper::registerFunction(&engine, proto, queryNearestNeighbor, "queryNearestNeighbor"); engine.setDefaultPrototype( qMetaTypeId<RSpatialIndexNavel*>(), *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RSpatialIndexNavel", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
// includes for base ecma wrapper classes void REcmaLinetypeCombo::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RLinetypeCombo*) 0))); protoCreated = true; } // primary base class QComboBox: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<QComboBox*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class QComboBox REcmaHelper::registerFunction(&engine, proto, getQComboBox, "getQComboBox"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, init, "init"); REcmaHelper::registerFunction(&engine, proto, reinit, "reinit"); REcmaHelper::registerFunction(&engine, proto, getLinetypePattern, "getLinetypePattern"); REcmaHelper::registerFunction(&engine, proto, getLinetypePatternAt, "getLinetypePatternAt"); REcmaHelper::registerFunction(&engine, proto, setLinetypePattern, "setLinetypePattern"); REcmaHelper::registerFunction(&engine, proto, getOnlyFixed, "getOnlyFixed"); REcmaHelper::registerFunction(&engine, proto, setOnlyFixed, "setOnlyFixed"); REcmaHelper::registerFunction(&engine, proto, linetypePatternChanged, "linetypePatternChanged"); engine.setDefaultPrototype( qMetaTypeId<RLinetypeCombo*>(), *proto); qScriptRegisterMetaType< RLinetypeCombo*>( &engine, toScriptValue, fromScriptValue, *proto); QScriptValue ctor = engine.newFunction(createEcma, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RLinetypeCombo", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
// includes for base ecma wrapper classes void REcmaImporter::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RImporter*) 0))); protoCreated = true; } QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, startImport, "startImport"); REcmaHelper::registerFunction(&engine, proto, endImport, "endImport"); REcmaHelper::registerFunction(&engine, proto, importObject, "importObject"); REcmaHelper::registerFunction(&engine, proto, setCurrentBlockId, "setCurrentBlockId"); REcmaHelper::registerFunction(&engine, proto, getCurrentBlockId, "getCurrentBlockId"); REcmaHelper::registerFunction(&engine, proto, getDocument, "getDocument"); REcmaHelper::registerFunction(&engine, proto, setDocument, "setDocument"); REcmaHelper::registerFunction(&engine, proto, setKnownVariable, "setKnownVariable"); engine.setDefaultPrototype( qMetaTypeId<RImporter*>(), *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RImporter", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
// includes for base ecma wrapper classes void REcmaLinetypePattern::init(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RLinetypePattern*) 0))); protoCreated = true; } QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // copy: REcmaHelper::registerFunction(&engine, proto, copy, "copy"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, set, "set"); REcmaHelper::registerFunction(&engine, proto, isValid, "isValid"); REcmaHelper::registerFunction(&engine, proto, getNumDashes, "getNumDashes"); REcmaHelper::registerFunction(&engine, proto, getPatternLength, "getPatternLength"); REcmaHelper::registerFunction(&engine, proto, getDashLengthAt, "getDashLengthAt"); REcmaHelper::registerFunction(&engine, proto, getLargestGap, "getLargestGap"); REcmaHelper::registerFunction(&engine, proto, hasDashAt, "hasDashAt"); REcmaHelper::registerFunction(&engine, proto, getDelta, "getDelta"); REcmaHelper::registerFunction(&engine, proto, isSymmetrical, "isSymmetrical"); REcmaHelper::registerFunction(&engine, proto, scale, "scale"); REcmaHelper::registerFunction(&engine, proto, operator_assign, "operator_assign"); REcmaHelper::registerFunction(&engine, proto, equals, "equals"); engine.setDefaultPrototype( qMetaTypeId<RLinetypePattern*>(), *proto); engine.setDefaultPrototype(qMetaTypeId< RLinetypePattern > (), *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RLinetypePattern", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
void REcmaPointEntity::init(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RPointEntity*) 0))); protoCreated = true; } // primary base class REntity: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<REntity*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class REntity REcmaHelper::registerFunction(&engine, proto, getREntity, "getREntity"); // conversion for base class RObject REcmaHelper::registerFunction(&engine, proto, getRObject, "getRObject"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, clone, "clone"); REcmaHelper::registerFunction(&engine, proto, getType, "getType"); REcmaHelper::registerFunction(&engine, proto, setProperty, "setProperty"); REcmaHelper::registerFunction(&engine, proto, getProperty, "getProperty"); REcmaHelper::registerFunction(&engine, proto, exportEntity, "exportEntity"); REcmaHelper::registerFunction(&engine, proto, getData, "getData"); REcmaHelper::registerFunction(&engine, proto, getPosition, "getPosition"); engine.setDefaultPrototype( qMetaTypeId<RPointEntity*>(), *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: REcmaHelper::registerFunction(&engine, &ctor, init, "init"); // static properties: ctor.setProperty("PropertyCustom", qScriptValueFromValue(&engine, RPointEntity::PropertyCustom), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyHandle", qScriptValueFromValue(&engine, RPointEntity::PropertyHandle), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyType", qScriptValueFromValue(&engine, RPointEntity::PropertyType), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyBlock", qScriptValueFromValue(&engine, RPointEntity::PropertyBlock), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLayer", qScriptValueFromValue(&engine, RPointEntity::PropertyLayer), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLinetype", qScriptValueFromValue(&engine, RPointEntity::PropertyLinetype), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLineweight", qScriptValueFromValue(&engine, RPointEntity::PropertyLineweight), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyColor", qScriptValueFromValue(&engine, RPointEntity::PropertyColor), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyDrawOrder", qScriptValueFromValue(&engine, RPointEntity::PropertyDrawOrder), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyPositionX", qScriptValueFromValue(&engine, RPointEntity::PropertyPositionX), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyPositionY", qScriptValueFromValue(&engine, RPointEntity::PropertyPositionY), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyPositionZ", qScriptValueFromValue(&engine, RPointEntity::PropertyPositionZ), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RPointEntity", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
void REcmaLeaderData::init(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RLeaderData*) 0))); protoCreated = true; } // primary base class REntityData: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<REntityData*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* REcmaPolyline::init(engine, proto); */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class REntityData REcmaHelper::registerFunction(&engine, proto, getREntityData, "getREntityData"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, castToShape, "castToShape"); REcmaHelper::registerFunction(&engine, proto, getDimasz, "getDimasz"); REcmaHelper::registerFunction(&engine, proto, getDimscale, "getDimscale"); REcmaHelper::registerFunction(&engine, proto, setArrowHead, "setArrowHead"); REcmaHelper::registerFunction(&engine, proto, hasArrowHead, "hasArrowHead"); REcmaHelper::registerFunction(&engine, proto, getEndPoint, "getEndPoint"); REcmaHelper::registerFunction(&engine, proto, getStartPoint, "getStartPoint"); REcmaHelper::registerFunction(&engine, proto, countVertices, "countVertices"); REcmaHelper::registerFunction(&engine, proto, countSegments, "countSegments"); REcmaHelper::registerFunction(&engine, proto, appendVertex, "appendVertex"); REcmaHelper::registerFunction(&engine, proto, getReferencePoints, "getReferencePoints"); REcmaHelper::registerFunction(&engine, proto, moveReferencePoint, "moveReferencePoint"); REcmaHelper::registerFunction(&engine, proto, getExploded, "getExploded"); REcmaHelper::registerFunction(&engine, proto, getShapes, "getShapes"); REcmaHelper::registerFunction(&engine, proto, getArrowShape, "getArrowShape"); engine.setDefaultPrototype( qMetaTypeId<RLeaderData*>(), *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RLeaderData", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
void tst_QScriptContext::throwError() { QScriptEngine eng; { QScriptValue fun = eng.newFunction(throw_Error); eng.globalObject().setProperty("throw_Error", fun); QScriptValue result = eng.evaluate("throw_Error()"); QCOMPARE(eng.hasUncaughtException(), true); QCOMPARE(result.isError(), true); QCOMPARE(result.toString(), QString("Error: foo")); } { QScriptValue fun = eng.newFunction(throw_TypeError); eng.globalObject().setProperty("throw_TypeError", fun); QScriptValue result = eng.evaluate("throw_TypeError()"); QCOMPARE(eng.hasUncaughtException(), true); QCOMPARE(result.isError(), true); QCOMPARE(result.toString(), QString("TypeError: foo")); } { QScriptValue fun = eng.newFunction(throw_ReferenceError); eng.globalObject().setProperty("throw_ReferenceError", fun); QScriptValue result = eng.evaluate("throw_ReferenceError()"); QCOMPARE(eng.hasUncaughtException(), true); QCOMPARE(result.isError(), true); QCOMPARE(result.toString(), QString("ReferenceError: foo")); } { QScriptValue fun = eng.newFunction(throw_SyntaxError); eng.globalObject().setProperty("throw_SyntaxError", fun); QScriptValue result = eng.evaluate("throw_SyntaxError()"); QCOMPARE(eng.hasUncaughtException(), true); QCOMPARE(result.isError(), true); QCOMPARE(result.toString(), QString("SyntaxError: foo")); } { QScriptValue fun = eng.newFunction(throw_RangeError); eng.globalObject().setProperty("throw_RangeError", fun); QScriptValue result = eng.evaluate("throw_RangeError()"); QCOMPARE(eng.hasUncaughtException(), true); QCOMPARE(result.isError(), true); QCOMPARE(result.toString(), QString("RangeError: foo")); } { QScriptValue fun = eng.newFunction(throw_URIError); eng.globalObject().setProperty("throw_URIError", fun); QScriptValue result = eng.evaluate("throw_URIError()"); QCOMPARE(eng.hasUncaughtException(), true); QCOMPARE(result.isError(), true); QCOMPARE(result.toString(), QString("URIError: foo")); } { QScriptValue fun = eng.newFunction(throw_ErrorAndReturnUndefined); eng.globalObject().setProperty("throw_ErrorAndReturnUndefined", fun); QScriptValue result = eng.evaluate("throw_ErrorAndReturnUndefined()"); QVERIFY(eng.hasUncaughtException()); QVERIFY(result.isError()); QCOMPARE(result.toString(), QString("Error: foo")); } }
void REcmaRestrictAngleLength::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RRestrictAngleLength*) 0))); protoCreated = true; } // primary base class RSnapRestriction: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<RSnapRestriction*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class RSnapRestriction REcmaHelper::registerFunction(&engine, proto, getRSnapRestriction, "getRSnapRestriction"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, restrictSnap, "restrictSnap"); REcmaHelper::registerFunction(&engine, proto, setBaseAngle, "setBaseAngle"); REcmaHelper::registerFunction(&engine, proto, setAngle, "setAngle"); REcmaHelper::registerFunction(&engine, proto, setBaseLength, "setBaseLength"); REcmaHelper::registerFunction(&engine, proto, setLength, "setLength"); REcmaHelper::registerFunction(&engine, proto, setRestrictAngle, "setRestrictAngle"); REcmaHelper::registerFunction(&engine, proto, setRestrictLength, "setRestrictLength"); engine.setDefaultPrototype( qMetaTypeId<RRestrictAngleLength*>(), *proto); QScriptValue ctor = engine.newFunction(createEcma, *proto, 2); // static methods: // static properties: // enum values: ctor.setProperty("None", QScriptValue(RRestrictAngleLength::None), QScriptValue::ReadOnly); ctor.setProperty("Angle", QScriptValue(RRestrictAngleLength::Angle), QScriptValue::ReadOnly); ctor.setProperty("Length", QScriptValue(RRestrictAngleLength::Length), QScriptValue::ReadOnly); ctor.setProperty("AngleLength", QScriptValue(RRestrictAngleLength::AngleLength), QScriptValue::ReadOnly); // enum conversions: qScriptRegisterMetaType<RRestrictAngleLength::AngleLengthMode>( &engine, toScriptValueEnumAngleLengthMode, fromScriptValueEnumAngleLengthMode, ctor.property(QString::fromLatin1("prototype")) ); // init class: engine.globalObject().setProperty("RRestrictAngleLength", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
void REcmaSharedPointerAttributeEntity::init(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RAttributeEntityPointer*) 0))); protoCreated = true; } // primary base class RTextBasedEntity: proto->setPrototype(engine.defaultPrototype( qMetaTypeId<RTextBasedEntityPointer>())); /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // shared pointer support: REcmaHelper::registerFunction(&engine, proto, data, "data"); REcmaHelper::registerFunction(&engine, proto, isNull, "isNull"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class RTextBasedEntity REcmaHelper::registerFunction(&engine, proto, getRTextBasedEntity, "getRTextBasedEntity"); // conversion for base class REntity REcmaHelper::registerFunction(&engine, proto, getREntity, "getREntity"); // conversion for base class RObject REcmaHelper::registerFunction(&engine, proto, getRObject, "getRObject"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, clone, "clone"); REcmaHelper::registerFunction(&engine, proto, getType, "getType"); REcmaHelper::registerFunction(&engine, proto, getData, "getData"); REcmaHelper::registerFunction(&engine, proto, setData, "setData"); REcmaHelper::registerFunction(&engine, proto, setProperty, "setProperty"); REcmaHelper::registerFunction(&engine, proto, getProperty, "getProperty"); REcmaHelper::registerFunction(&engine, proto, exportEntity, "exportEntity"); REcmaHelper::registerFunction(&engine, proto, getTag, "getTag"); REcmaHelper::registerFunction(&engine, proto, setTag, "setTag"); engine.setDefaultPrototype( qMetaTypeId<RAttributeEntityPointer>(), *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: REcmaHelper::registerFunction(&engine, &ctor, init, "init"); // static properties: ctor.setProperty("PropertyCustom", qScriptValueFromValue(&engine, RAttributeEntity::PropertyCustom), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyHandle", qScriptValueFromValue(&engine, RAttributeEntity::PropertyHandle), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyType", qScriptValueFromValue(&engine, RAttributeEntity::PropertyType), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyBlock", qScriptValueFromValue(&engine, RAttributeEntity::PropertyBlock), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLayer", qScriptValueFromValue(&engine, RAttributeEntity::PropertyLayer), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLinetype", qScriptValueFromValue(&engine, RAttributeEntity::PropertyLinetype), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLineweight", qScriptValueFromValue(&engine, RAttributeEntity::PropertyLineweight), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyColor", qScriptValueFromValue(&engine, RAttributeEntity::PropertyColor), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyDrawOrder", qScriptValueFromValue(&engine, RAttributeEntity::PropertyDrawOrder), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyAngle", qScriptValueFromValue(&engine, RAttributeEntity::PropertyAngle), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyBold", qScriptValueFromValue(&engine, RAttributeEntity::PropertyBold), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyFontName", qScriptValueFromValue(&engine, RAttributeEntity::PropertyFontName), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyHAlign", qScriptValueFromValue(&engine, RAttributeEntity::PropertyHAlign), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyHeight", qScriptValueFromValue(&engine, RAttributeEntity::PropertyHeight), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyItalic", qScriptValueFromValue(&engine, RAttributeEntity::PropertyItalic), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLineSpacingFactor", qScriptValueFromValue(&engine, RAttributeEntity::PropertyLineSpacingFactor), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyPositionX", qScriptValueFromValue(&engine, RAttributeEntity::PropertyPositionX), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyPositionY", qScriptValueFromValue(&engine, RAttributeEntity::PropertyPositionY), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyPositionZ", qScriptValueFromValue(&engine, RAttributeEntity::PropertyPositionZ), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyTag", qScriptValueFromValue(&engine, RAttributeEntity::PropertyTag), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyText", qScriptValueFromValue(&engine, RAttributeEntity::PropertyText), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyVAlign", qScriptValueFromValue(&engine, RAttributeEntity::PropertyVAlign), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RAttributeEntityPointer", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
// includes for base ecma wrapper classes void REcmaPluginLoader::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RPluginLoader*) 0))); protoCreated = true; } QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: engine.setDefaultPrototype( qMetaTypeId<RPluginLoader*>(), *proto); QScriptValue ctor = engine.newFunction(createEcma, *proto, 2); // static methods: REcmaHelper::registerFunction(&engine, &ctor, getPluginSuffix, "getPluginSuffix"); REcmaHelper::registerFunction(&engine, &ctor, getPluginFiles, "getPluginFiles"); REcmaHelper::registerFunction(&engine, &ctor, loadPlugins, "loadPlugins"); REcmaHelper::registerFunction(&engine, &ctor, unloadPlugins, "unloadPlugins"); REcmaHelper::registerFunction(&engine, &ctor, unloadPlugin, "unloadPlugin"); REcmaHelper::registerFunction(&engine, &ctor, postInitPlugins, "postInitPlugins"); REcmaHelper::registerFunction(&engine, &ctor, countPlugins, "countPlugins"); REcmaHelper::registerFunction(&engine, &ctor, getPluginInfo, "getPluginInfo"); REcmaHelper::registerFunction(&engine, &ctor, getPluginsPath, "getPluginsPath"); REcmaHelper::registerFunction(&engine, &ctor, hasPlugin, "hasPlugin"); // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RPluginLoader", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
void REcmaRulerQt::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL) { proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RRulerQt*) 0))); protoCreated = true; } // primary base class QFrame: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<QFrame*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* REcmaRuler::initEcma(engine, proto); REcmaCoordinateListener::initEcma(engine, proto); */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class QFrame REcmaHelper::registerFunction(&engine, proto, getQFrame, "getQFrame"); // conversion for base class RRuler REcmaHelper::registerFunction(&engine, proto, getRRuler, "getRRuler"); // conversion for base class RCoordinateListener REcmaHelper::registerFunction(&engine, proto, getRCoordinateListener, "getRCoordinateListener"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties of secondary base class RRuler: // methods of secondary base class RRuler: REcmaHelper::registerFunction(&engine, proto, setGraphicsView, "setGraphicsView"); REcmaHelper::registerFunction(&engine, proto, getOrientation, "getOrientation"); // properties of secondary base class RCoordinateListener: // methods of secondary base class RCoordinateListener: // properties: // methods: REcmaHelper::registerFunction(&engine, proto, setOrientation, "setOrientation"); REcmaHelper::registerFunction(&engine, proto, sizeHint, "sizeHint"); REcmaHelper::registerFunction(&engine, proto, paintTick, "paintTick"); REcmaHelper::registerFunction(&engine, proto, getFont, "getFont"); REcmaHelper::registerFunction(&engine, proto, updateViewport, "updateViewport"); REcmaHelper::registerFunction(&engine, proto, updateCoordinate, "updateCoordinate"); engine.setDefaultPrototype( qMetaTypeId<RRulerQt*>(), *proto); qScriptRegisterMetaType< RRulerQt*>( &engine, toScriptValue, fromScriptValue, *proto); QScriptValue ctor = engine.newFunction(createEcma, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RRulerQt", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ) { delete proto; } }
void REcmaSharedPointerDimLinearEntity::init(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RDimLinearEntityPointer*) 0))); protoCreated = true; } // primary base class RDimensionEntity: proto->setPrototype(engine.defaultPrototype( qMetaTypeId<RDimensionEntityPointer>())); /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // shared pointer support: REcmaHelper::registerFunction(&engine, proto, data, "data"); REcmaHelper::registerFunction(&engine, proto, isNull, "isNull"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class RDimensionEntity REcmaHelper::registerFunction(&engine, proto, getRDimensionEntity, "getRDimensionEntity"); // conversion for base class REntity REcmaHelper::registerFunction(&engine, proto, getREntity, "getREntity"); // conversion for base class RObject REcmaHelper::registerFunction(&engine, proto, getRObject, "getRObject"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, setProperty, "setProperty"); REcmaHelper::registerFunction(&engine, proto, getProperty, "getProperty"); REcmaHelper::registerFunction(&engine, proto, getData, "getData"); REcmaHelper::registerFunction(&engine, proto, setExtensionPoint1, "setExtensionPoint1"); REcmaHelper::registerFunction(&engine, proto, getExtensionPoint1, "getExtensionPoint1"); REcmaHelper::registerFunction(&engine, proto, setExtensionPoint2, "setExtensionPoint2"); REcmaHelper::registerFunction(&engine, proto, getExtensionPoint2, "getExtensionPoint2"); engine.setDefaultPrototype( qMetaTypeId<RDimLinearEntityPointer>(), *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: REcmaHelper::registerFunction(&engine, &ctor, init, "init"); // static properties: ctor.setProperty("PropertyCustom", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyCustom), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyHandle", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyHandle), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyType", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyType), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyBlock", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyBlock), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLayer", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyLayer), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLinetype", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyLinetype), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLineweight", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyLineweight), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyColor", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyColor), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyDrawOrder", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyDrawOrder), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyMiddleOfTextX", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyMiddleOfTextX), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyMiddleOfTextY", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyMiddleOfTextY), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyMiddleOfTextZ", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyMiddleOfTextZ), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyText", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyText), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyUpperTolerance", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyUpperTolerance), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLowerTolerance", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyLowerTolerance), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyMeasuredValue", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyMeasuredValue), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyLinearFactor", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyLinearFactor), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyAutoTextPos", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyAutoTextPos), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyFontName", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyFontName), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyDimensionLinePosX", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyDimensionLinePosX), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyDimensionLinePosY", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyDimensionLinePosY), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyDimensionLinePosZ", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyDimensionLinePosZ), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyExtensionPoint1X", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyExtensionPoint1X), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyExtensionPoint1Y", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyExtensionPoint1Y), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyExtensionPoint1Z", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyExtensionPoint1Z), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyExtensionPoint2X", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyExtensionPoint2X), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyExtensionPoint2Y", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyExtensionPoint2Y), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); ctor.setProperty("PropertyExtensionPoint2Z", qScriptValueFromValue(&engine, RDimLinearEntity::PropertyExtensionPoint2Z), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RDimLinearEntityPointer", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
// includes for base ecma wrapper classes void REcmaSharedPointerDirected::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RDirectedPointer*) 0))); protoCreated = true; } QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // shared pointer support: REcmaHelper::registerFunction(&engine, proto, data, "data"); REcmaHelper::registerFunction(&engine, proto, isNull, "isNull"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, getDirection1, "getDirection1"); REcmaHelper::registerFunction(&engine, proto, getDirection2, "getDirection2"); REcmaHelper::registerFunction(&engine, proto, getSideOfPoint, "getSideOfPoint"); REcmaHelper::registerFunction(&engine, proto, getStartPoint, "getStartPoint"); REcmaHelper::registerFunction(&engine, proto, getEndPoint, "getEndPoint"); REcmaHelper::registerFunction(&engine, proto, reverse, "reverse"); REcmaHelper::registerFunction(&engine, proto, trimStartPoint, "trimStartPoint"); REcmaHelper::registerFunction(&engine, proto, trimEndPoint, "trimEndPoint"); REcmaHelper::registerFunction(&engine, proto, getTrimEnd, "getTrimEnd"); REcmaHelper::registerFunction(&engine, proto, getDistanceFromStart, "getDistanceFromStart"); engine.setDefaultPrototype( qMetaTypeId<RDirectedPointer>(), *proto); QScriptValue ctor = engine.newFunction(createEcma, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RDirectedPointer", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
void REcmaInterTransactionListenerAdapter::init(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RInterTransactionListenerAdapter*) 0))); protoCreated = true; } // primary base class QObject: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<QObject*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* REcmaInterTransactionListener::init(engine, proto); */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class QObject REcmaHelper::registerFunction(&engine, proto, getQObject, "getQObject"); // conversion for base class RInterTransactionListener REcmaHelper::registerFunction(&engine, proto, getRInterTransactionListener, "getRInterTransactionListener"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties of secondary base class RInterTransactionListener: // methods of secondary base class RInterTransactionListener: // properties: // methods: REcmaHelper::registerFunction(&engine, proto, updateInterTransactionListener, "updateInterTransactionListener"); engine.setDefaultPrototype( qMetaTypeId<RInterTransactionListenerAdapter*>(), *proto); qScriptRegisterMetaType< RInterTransactionListenerAdapter*>( &engine, toScriptValue, fromScriptValue, *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RInterTransactionListenerAdapter", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
void REcmaPointData::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RPointData*) 0))); protoCreated = true; } // primary base class REntityData: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<REntityData*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* REcmaPoint::initEcma(engine, proto); */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // copy: REcmaHelper::registerFunction(&engine, proto, copy, "copy"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class REntityData REcmaHelper::registerFunction(&engine, proto, getREntityData, "getREntityData"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, getPosition, "getPosition"); REcmaHelper::registerFunction(&engine, proto, getReferencePoints, "getReferencePoints"); REcmaHelper::registerFunction(&engine, proto, moveReferencePoint, "moveReferencePoint"); REcmaHelper::registerFunction(&engine, proto, castToShape, "castToShape"); REcmaHelper::registerFunction(&engine, proto, getShapes, "getShapes"); engine.setDefaultPrototype( qMetaTypeId<RPointData*>(), *proto); engine.setDefaultPrototype(qMetaTypeId< RPointData > (), *proto); QScriptValue ctor = engine.newFunction(createEcma, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RPointData", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
void REcmaAddObjectsOperation::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL) { proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RAddObjectsOperation*) 0))); protoCreated = true; } // primary base class ROperation: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<ROperation*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class ROperation REcmaHelper::registerFunction(&engine, proto, getROperation, "getROperation"); // conversion for base class RRequireHeap REcmaHelper::registerFunction(&engine, proto, getRRequireHeap, "getRRequireHeap"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, replaceObject, "replaceObject"); REcmaHelper::registerFunction(&engine, proto, getObject, "getObject"); REcmaHelper::registerFunction(&engine, proto, endCycle, "endCycle"); REcmaHelper::registerFunction(&engine, proto, addObject, "addObject"); REcmaHelper::registerFunction(&engine, proto, deleteObject, "deleteObject"); REcmaHelper::registerFunction(&engine, proto, apply, "apply"); REcmaHelper::registerFunction(&engine, proto, getPreviewCounter, "getPreviewCounter"); REcmaHelper::registerFunction(&engine, proto, setLimitPreview, "setLimitPreview"); REcmaHelper::registerFunction(&engine, proto, isEmpty, "isEmpty"); engine.setDefaultPrototype( qMetaTypeId<RAddObjectsOperation*>(), *proto); QScriptValue ctor = engine.newFunction(createEcma, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RAddObjectsOperation", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ) { delete proto; } }
// includes for base ecma wrapper classes void REcmaFileImporterRegistry::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RFileImporterRegistry*) 0))); protoCreated = true; } QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: engine.setDefaultPrototype( qMetaTypeId<RFileImporterRegistry*>(), *proto); QScriptValue ctor = engine.newFunction(createEcma, *proto, 2); // static methods: REcmaHelper::registerFunction(&engine, &ctor, registerFileImporter, "registerFileImporter"); REcmaHelper::registerFunction(&engine, &ctor, unregisterFileImporter, "unregisterFileImporter"); REcmaHelper::registerFunction(&engine, &ctor, getFileImporter, "getFileImporter"); REcmaHelper::registerFunction(&engine, &ctor, getFilterStrings, "getFilterStrings"); REcmaHelper::registerFunction(&engine, &ctor, hasFileImporter, "hasFileImporter"); REcmaHelper::registerFunction(&engine, &ctor, getFilterExtensions, "getFilterExtensions"); REcmaHelper::registerFunction(&engine, &ctor, getFilterExtensionPatterns, "getFilterExtensionPatterns"); // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RFileImporterRegistry", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
// includes for base ecma wrapper classes void REcmaCharacterWidget::init(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RCharacterWidget*) 0))); protoCreated = true; } // primary base class QWidget: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<QWidget*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class QWidget REcmaHelper::registerFunction(&engine, proto, getQWidget, "getQWidget"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, sizeHint, "sizeHint"); REcmaHelper::registerFunction(&engine, proto, getDisplayFont, "getDisplayFont"); REcmaHelper::registerFunction(&engine, proto, updateFont, "updateFont"); REcmaHelper::registerFunction(&engine, proto, updateSize, "updateSize"); REcmaHelper::registerFunction(&engine, proto, updateStyle, "updateStyle"); REcmaHelper::registerFunction(&engine, proto, updateFontMerging, "updateFontMerging"); engine.setDefaultPrototype( qMetaTypeId<RCharacterWidget*>(), *proto); qScriptRegisterMetaType< RCharacterWidget*>( &engine, toScriptValue, fromScriptValue, *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RCharacterWidget", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
void REcmaSharedPointerLinetype::init(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RLinetypePointer*) 0))); protoCreated = true; } // primary base class RObject: proto->setPrototype(engine.defaultPrototype( qMetaTypeId<RObjectPointer>())); /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // copy: REcmaHelper::registerFunction(&engine, proto, copy, "copy"); // shared pointer support: REcmaHelper::registerFunction(&engine, proto, data, "data"); REcmaHelper::registerFunction(&engine, proto, isNull, "isNull"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class RObject REcmaHelper::registerFunction(&engine, proto, getRObject, "getRObject"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, clone, "clone"); REcmaHelper::registerFunction(&engine, proto, getName, "getName"); REcmaHelper::registerFunction(&engine, proto, setName, "setName"); REcmaHelper::registerFunction(&engine, proto, isValid, "isValid"); REcmaHelper::registerFunction(&engine, proto, getProperty, "getProperty"); REcmaHelper::registerFunction(&engine, proto, setProperty, "setProperty"); REcmaHelper::registerFunction(&engine, proto, isSelectedForPropertyEditing, "isSelectedForPropertyEditing"); REcmaHelper::registerFunction(&engine, proto, equals, "equals"); REcmaHelper::registerFunction(&engine, proto, operator_not_assign, "operator_not_assign"); REcmaHelper::registerFunction(&engine, proto, operator_less, "operator_less"); engine.setDefaultPrototype( qMetaTypeId<RLinetypePointer>(), *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: REcmaHelper::registerFunction(&engine, &ctor, init, "init"); REcmaHelper::registerFunction(&engine, &ctor, getList, "getList"); REcmaHelper::registerFunction(&engine, &ctor, getIcon, "getIcon"); REcmaHelper::registerFunction(&engine, &ctor, getTitle, "getTitle"); // static properties: ctor.setProperty("PropertyName", qScriptValueFromValue(&engine, RLinetype::PropertyName), QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RLinetypePointer", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
void tst_QScriptContext::arguments() { QScriptEngine eng; { QScriptValue args = eng.currentContext()->argumentsObject(); QVERIFY(args.isObject()); QCOMPARE(args.property("length").toInt32(), 0); } { QScriptValue fun = eng.newFunction(get_arguments); eng.globalObject().setProperty("get_arguments", fun); } for (int x = 0; x < 2; ++x) { QString prefix; if (x == 0) prefix = ""; else prefix = "new "; { QScriptValue result = eng.evaluate(prefix+"get_arguments()"); QCOMPARE(result.isArray(), true); QCOMPARE(result.property("length").toUInt32(), quint32(0)); } { QScriptValue result = eng.evaluate(prefix+"get_arguments(123)"); QCOMPARE(result.isArray(), true); QCOMPARE(result.property("length").toUInt32(), quint32(1)); QCOMPARE(result.property("0").isNumber(), true); QCOMPARE(result.property("0").toNumber(), 123.0); } { QScriptValue result = eng.evaluate(prefix+"get_arguments(\"ciao\", null, true, undefined)"); QCOMPARE(result.isArray(), true); QCOMPARE(result.property("length").toUInt32(), quint32(4)); QCOMPARE(result.property("0").isString(), true); QCOMPARE(result.property("0").toString(), QString("ciao")); QCOMPARE(result.property("1").isNull(), true); QCOMPARE(result.property("2").isBoolean(), true); QCOMPARE(result.property("2").toBoolean(), true); QCOMPARE(result.property("3").isUndefined(), true); } { QScriptValue fun = eng.newFunction(get_argumentsObject); eng.globalObject().setProperty("get_argumentsObject", fun); } { QScriptValue fun = eng.evaluate("get_argumentsObject"); QCOMPARE(fun.isFunction(), true); QScriptValue result = eng.evaluate(prefix+"get_argumentsObject()"); QCOMPARE(result.isArray(), false); QVERIFY(result.isObject()); QCOMPARE(result.property("length").toUInt32(), quint32(0)); QCOMPARE(result.propertyFlags("length"), QScriptValue::SkipInEnumeration); QCOMPARE(result.property("callee").strictlyEquals(fun), true); QCOMPARE(result.propertyFlags("callee"), QScriptValue::SkipInEnumeration); QScriptValue replacedCallee(&eng, 123); result.setProperty("callee", replacedCallee); QVERIFY(result.property("callee").equals(replacedCallee)); QScriptValue replacedLength(&eng, 456); result.setProperty("length", replacedLength); QVERIFY(result.property("length").equals(replacedLength)); result.setProperty("callee", QScriptValue()); QVERIFY(!result.property("callee").isValid()); result.setProperty("length", QScriptValue()); QVERIFY(!result.property("length").isValid()); } { QScriptValue result = eng.evaluate(prefix+"get_argumentsObject(123)"); eng.evaluate("function nestedArg(x,y,z) { var w = get_argumentsObject('ABC' , x+y+z); return w; }"); QScriptValue result2 = eng.evaluate("nestedArg(1, 'a', 2)"); QCOMPARE(result.isArray(), false); QVERIFY(result.isObject()); QCOMPARE(result.property("length").toUInt32(), quint32(1)); QCOMPARE(result.property("0").isNumber(), true); QCOMPARE(result.property("0").toNumber(), 123.0); QVERIFY(result2.isObject()); QCOMPARE(result2.property("length").toUInt32(), quint32(2)); QCOMPARE(result2.property("0").toString(), QString::fromLatin1("ABC")); QCOMPARE(result2.property("1").toString(), QString::fromLatin1("1a2")); } { QScriptValue result = eng.evaluate(prefix+"get_argumentsObject(\"ciao\", null, true, undefined)"); QCOMPARE(result.isArray(), false); QCOMPARE(result.property("length").toUInt32(), quint32(4)); QCOMPARE(result.property("0").isString(), true); QCOMPARE(result.property("0").toString(), QString("ciao")); QCOMPARE(result.property("1").isNull(), true); QCOMPARE(result.property("2").isBoolean(), true); QCOMPARE(result.property("2").toBoolean(), true); QCOMPARE(result.property("3").isUndefined(), true); } // arguments object returned from script { QScriptValue result = eng.evaluate("(function() { return arguments; })(123)"); QCOMPARE(result.isArray(), false); QVERIFY(result.isObject()); QCOMPARE(result.property("length").toUInt32(), quint32(1)); QCOMPARE(result.property("0").isNumber(), true); QCOMPARE(result.property("0").toNumber(), 123.0); } { QScriptValue result = eng.evaluate("(function() { return arguments; })('ciao', null, true, undefined)"); QCOMPARE(result.isArray(), false); QCOMPARE(result.property("length").toUInt32(), quint32(4)); QCOMPARE(result.property("0").isString(), true); QCOMPARE(result.property("0").toString(), QString("ciao")); QCOMPARE(result.property("1").isNull(), true); QCOMPARE(result.property("2").isBoolean(), true); QCOMPARE(result.property("2").toBoolean(), true); QCOMPARE(result.property("3").isUndefined(), true); } } }
void REcmaSnapIntersection::initEcma(QScriptEngine& engine, QScriptValue* proto ) { bool protoCreated = false; if(proto == NULL){ proto = new QScriptValue(engine.newVariant(qVariantFromValue( (RSnapIntersection*) 0))); protoCreated = true; } // primary base class RSnap: QScriptValue dpt = engine.defaultPrototype( qMetaTypeId<RSnap*>()); if (dpt.isValid()) { proto->setPrototype(dpt); } /* */ QScriptValue fun; // toString: REcmaHelper::registerFunction(&engine, proto, toString, "toString"); // destroy: REcmaHelper::registerFunction(&engine, proto, destroy, "destroy"); // conversion for base class RSnap REcmaHelper::registerFunction(&engine, proto, getRSnap, "getRSnap"); // get class name REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName"); // conversion to all base classes (multiple inheritance): REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses"); // properties: // methods: REcmaHelper::registerFunction(&engine, proto, snap, "snap"); engine.setDefaultPrototype( qMetaTypeId<RSnapIntersection*>(), *proto); QScriptValue ctor = engine.newFunction(create, *proto, 2); // static methods: // static properties: // enum values: // enum conversions: // init class: engine.globalObject().setProperty("RSnapIntersection", ctor, QScriptValue::SkipInEnumeration); if( protoCreated ){ delete proto; } }
//! [34] //! [35] QScriptValue Person_prototype_toString(QScriptContext *context, QScriptEngine *engine) { QString name = context->thisObject().property("name").toString(); QString result = QString::fromLatin1("Person(name: %0)").arg(name); return result; } //! [35] //! [36] QScriptEngine engine; QScriptValue ctor = engine.newFunction(Person_ctor); ctor.property("prototype").setProperty("toString", engine.newFunction(Person_prototype_toString)); QScriptValue global = engine.globalObject(); global.setProperty("Person", ctor); //! [36] //! [37] QScriptValue Employee_ctor(QScriptContext *context, QScriptEngine *engine) { QScriptValue super = context->callee().property("prototype").property("constructor"); super.call(context->thisObject(), QScriptValueList() << context->argument(0)); context->thisObject().setProperty("salary", context->argument(1)); return engine->undefinedValue(); } //! [37]