24 #ifndef QSCRIPTENGINE_H
25 #define QSCRIPTENGINE_H
52 class QScriptEnginePrivate;
62 #endif // QT_NO_QOBJECT
74 class QScriptSyntaxCheckResultPrivate;
88 int errorLineNumber()
const;
89 int errorColumnNumber()
const;
101 friend class QScriptEnginePrivate;
104 class Q_SCRIPT_EXPORT QScriptEngine
105 #ifndef QT_NO_QOBJECT
109 #ifndef QT_NO_QOBJECT
120 ExcludeChildObjects = 0x0001,
121 ExcludeSuperClassMethods = 0x0002,
122 ExcludeSuperClassProperties = 0x0004,
123 ExcludeSuperClassContents = 0x0006,
124 SkipMethodsInEnumeration = 0x0008,
125 ExcludeDeleteLater = 0x0010,
126 ExcludeSlots = 0x0020,
128 AutoCreateDynamicProperties = 0x0100,
129 PreferExistingWrapperObject = 0x0200
131 Q_DECLARE_FLAGS(QObjectWrapOptions, QObjectWrapOption)
134 #ifndef QT_NO_QOBJECT
135 explicit QScriptEngine(
QObject *parent);
137 virtual ~QScriptEngine();
153 bool isEvaluating()
const;
156 bool hasUncaughtException()
const;
158 int uncaughtExceptionLineNumber()
const;
160 void clearExceptions();
166 typedef QScriptValue (*FunctionWithArgSignature)(QScriptContext *, QScriptEngine *,
void *);
171 QScriptValue newFunction(FunctionWithArgSignature signature,
void *arg);
188 #ifndef QT_NO_QOBJECT
190 const QObjectWrapOptions &options = 0);
193 const QObjectWrapOptions &options = 0);
197 template <
class T>
QScriptValue scriptValueFromQMetaObject();
199 #endif // QT_NO_QOBJECT
204 void setDefaultPrototype(
int metaTypeId,
const QScriptValue &prototype);
207 typedef QScriptValue (*MarshalFunction)(QScriptEngine *,
const void *);
212 template <
typename T>
217 template <
typename T>
223 void installTranslatorFunctions(
const QScriptValue &
object = QScriptValue());
225 QScriptValue importExtension(
const QString &extension);
229 void collectGarbage();
230 void reportAdditionalMemoryCost(
int size);
232 void setProcessEventsInterval(
int interval);
233 int processEventsInterval()
const;
235 void setAgent(QScriptEngineAgent *agent);
236 QScriptEngineAgent *agent()
const;
239 QScriptValue toObject(
const QScriptValue &
value);
241 QScriptValue objectById(
qint64 id)
const;
243 #ifndef QT_NO_QOBJECT
245 void signalHandlerException(
const QScriptValue &exception);
249 QScriptValue create(
int type,
const void *ptr);
251 bool convert(
const QScriptValue &
value,
int type,
void *ptr);
252 static bool convertV2(
const QScriptValue &
value,
int type,
void *ptr);
254 void registerCustomType(
int type, MarshalFunction mf, DemarshalFunction df,
255 const QScriptValue &prototype);
258 int, MarshalFunction, DemarshalFunction,
const QScriptValue &);
268 QScriptEngine(QScriptEnginePrivate &dd);
270 QScriptEngine(QScriptEnginePrivate &dd,
QObject *parent = 0);
274 Q_DECLARE_PRIVATE(QScriptEngine)
275 Q_DISABLE_COPY(QScriptEngine)
276 #ifndef QT_NO_QOBJECT
281 #ifndef QT_NO_QOBJECT
283 #define Q_SCRIPT_DECLARE_QMETAOBJECT(T, _Arg1) \
284 template<> inline QScriptValue qscriptQMetaObjectConstructor<T>(QScriptContext *ctx, QScriptEngine *eng, T *) \
286 _Arg1 arg1 = qscriptvalue_cast<_Arg1> (ctx->argument(0)); \
287 T* t = new T(arg1); \
288 if (ctx->isCalledAsConstructor()) \
289 return eng->newQObject(ctx->thisObject(), t, QScriptEngine::AutoOwnership); \
290 QScriptValue o = eng->newQObject(t, QScriptEngine::AutoOwnership); \
291 o.setPrototype(ctx->callee().property(QString::fromLatin1("prototype"))); \
297 typedef QScriptValue(*ConstructPtr)(QScriptContext *, QScriptEngine *, T *);
298 ConstructPtr cptr = qscriptQMetaObjectConstructor<T>;
299 return newQMetaObject(&T::staticMetaObject,
300 newFunction(reinterpret_cast<FunctionWithArgSignature>(cptr), 0));
305 inline QT_DEPRECATED QScriptValue qScriptValueFromQMetaObject(
306 QScriptEngine *engine
312 return engine->scriptValueFromQMetaObject<T>();
316 #endif // QT_NO_QOBJECT
321 return QScriptValue();
323 return engine->create(type, ptr);
326 template <
typename T>
340 return QScriptEngine::convertV2(value, type, ptr);
347 const int id = qMetaTypeId<T>();
352 return qvariant_cast<T>(value.
toVariant());
360 return value.toVariant();
364 template <
typename T>
365 inline QT_DEPRECATED T qScriptValueToValue(
const QScriptValue &
value)
374 const QScriptValue &prototype)
376 eng->registerCustomType(type, mf, df, prototype);
382 QScriptValue (*toScriptValue)(QScriptEngine *,
const T &
t),
383 void (*fromScriptValue)(
const QScriptValue &, T &t),
384 const QScriptValue &prototype = QScriptValue()
390 const int id = qRegisterMetaType<T>();
393 eng,
id, reinterpret_cast<QScriptEngine::MarshalFunction>(toScriptValue),
394 reinterpret_cast<QScriptEngine::DemarshalFunction>(fromScriptValue),
400 template <
class Container>
404 typename Container::const_iterator begin = cont.begin();
405 typename Container::const_iterator
end = cont.end();
406 typename Container::const_iterator it;
408 for (it = begin, i = 0; it !=
end; ++it, ++i)
413 template <
class Container>
418 QScriptValue item = value.
property(i);
419 cont.push_back(qscriptvalue_cast<typename Container::value_type>(item));
425 QScriptEngine *engine,
426 const QScriptValue &prototype = QScriptValue()
436 #ifndef QT_NO_QOBJECT
438 const QScriptValue &receiver,
439 const QScriptValue &
function);
441 const QScriptValue &receiver,
442 const QScriptValue &
function);
443 #endif // QT_NO_QOBJECT
445 Q_DECLARE_OPERATORS_FOR_FLAGS(QScriptEngine::QObjectWrapOptions)
451 #endif // QSCRIPTENGINE_H
QScriptValue newArray(uint length=0)
GLuint GLuint GLsizei GLenum type
void(* DemarshalFunction)(const QScriptValue &, void *)
T qscriptvalue_cast(const QScriptValue &)
Q_SCRIPT_EXPORT bool qScriptDisconnect(QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
State
The state the media producing object is in at the moment.
T fromScriptValue(const QScriptValue &value)
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
#define Q_PRIVATE_SLOT(d, signature)
QScriptValue qScriptValueFromValue< QVariant >(QScriptEngine *engine, const QVariant &v)
QScriptValue toScriptValue(const T &value)
QScriptValue scriptValueFromQMetaObject()
QScriptValue qScriptValueFromValue(QScriptEngine *, const T &)
int qScriptRegisterSequenceMetaType(QScriptEngine *engine, const QScriptValue &prototype=QScriptValue(), T *=0)
QScriptValue qScriptValueFromSequence(QScriptEngine *eng, const Container &cont)
#define QT_BEGIN_NAMESPACE
GLsizei GLsizei GLenum GLenum const GLvoid * data
QScriptValue(* MarshalFunction)(QScriptEngine *, const void *)
void qScriptRegisterMetaType_helper(QScriptEngine *eng, int type, QScriptEngine::MarshalFunction mf, QScriptEngine::DemarshalFunction df, const QScriptValue &prototype)
bool qscriptvalue_cast_helper(const QScriptValue &value, int type, void *ptr)
GLuint GLsizei GLsizei * length
QScriptValue qscriptQMetaObjectConstructor(QScriptContext *, QScriptEngine *, T *)
GLsizei const GLfloat * value
Q_SCRIPT_EXPORT bool qScriptConnect(QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
GLubyte GLubyte GLubyte a
int qScriptRegisterMetaType(QScriptEngine *eng, QScriptValue(*toScriptValue)(QScriptEngine *, const T &t), void(*fromScriptValue)(const QScriptValue &, T &t), const QScriptValue &prototype=QScriptValue(), T *=0)
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
void qScriptValueToSequence(const QScriptValue &value, Container &cont)
QVariant toVariant() const
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
QScriptValue qScriptValueFromValue_helper(QScriptEngine *engine, int type, const void *ptr)