Преглед на файлове

Units can be passed through signals to script handlers

Neal Wilson преди 11 години
родител
ревизия
09aa7caad8
променени са 1 файла, в които са добавени 29 реда и са изтрити 0 реда
  1. 29
    0
      src/units.w

+ 29
- 0
src/units.w Целия файл

@@ -370,3 +370,32 @@ enumeration.
370 370
 value = engine->newQMetaObject(&Units::staticMetaObject);
371 371
 engine->globalObject().setProperty("Units", value);
372 372
 
373
+@ While the above is sufficient for some uses, others require some additional
374
+work.
375
+
376
+@<Class declarations@>=
377
+Q_DECLARE_METATYPE(Units::Unit)
378
+
379
+@ A pair of conversion methods is required.
380
+
381
+@<Function prototypes for scripting@>=
382
+QScriptValue Unit_toScriptValue(QScriptEngine *engine, const Units::Unit &value);
383
+void Unit_fromScriptValue(const QScriptValue &sv, Units::Unit &value);
384
+
385
+@ These are implemented thusly.
386
+
387
+@<Functions for scripting@>=
388
+QScriptValue Unit_toScriptValue(QScriptEngine *engine, const Units::Unit &value)
389
+{
390
+	return engine->newVariant(QVariant(value));
391
+}
392
+
393
+void Unit_fromScriptValue(const QScriptValue &sv, Units::Unit &value)
394
+{
395
+	value = sv.toVariant().value<Units::Unit>();
396
+}
397
+
398
+@ These conversion functions are registered.
399
+
400
+@<Set up the scripting engine@>=
401
+qScriptRegisterMetaType(engine, Unit_toScriptValue, Unit_fromScriptValue);

Loading…
Отказ
Запис