1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-09 20:46:07 +01:00
LibrePilot/ground/src/shared/scriptwrapper
julien 37a66b2340 OP-12: Header update, still need to fill-in brief and module doxygen fields
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@281 ebee16cc-31ac-478f-84a7-5cbb03baadba
2010-03-10 22:36:47 +00:00
..
interface_wrap_helpers.h OP-12: Header update, still need to fill-in brief and module doxygen fields 2010-03-10 22:36:47 +00:00
README fix case issue 2010-02-01 16:17:22 +00:00
scriptwrapper.pri fix case issue 2010-02-01 16:17:22 +00:00
wrap_helpers.h OP-12: Header update, still need to fill-in brief and module doxygen fields 2010-03-10 22:36:47 +00:00

Some wrap helpers for Script support.

How to wrap an interface:
=========================

1) Prototypes (preferred)
-------------------------

- Interface must inherit QObjectInterface and be qvariant-castable, that is,
  declared as Q-MetaType.

- Register a prototype with the engine for each interface:
  - Provide an informative toString()-slot.
  - Use properties and slots for everything, can be non-void as well
  - Accessors to interfaces should be properties.

- In the toScriptValue() function passed on to qScriptRegisterMetaType, create
  an newQObject on the QObject obtained from the QObjectInterface and assign it the prototype
  registered for the interface (obtained  from the engine) using QScriptValue::setDefaultPrototype
  The prototype can then qobject (-extension)-cast to the interface as each
  implementing class returns 'this' as qObject() of QObjectInterface.

- If sequences of the  interface are used, declare them as Q-MetaType
  and do qScriptRegisterSequenceMetaType().

The template  registerQObjectInterface does the magic.

2) Manually bless a script value with properties
------------------------------------------------

Typically, a qobject-derived wrapper will be used
that provides an accessor to the wrapped class.
The wrapper contains a QScriptValue 'm_self' which
typically is initialized using:

- engine.newQObject(this, QScriptEngine::ScriptOwnership))
  for interfaces that are always present.

- m_self(engine.newQObject(this, QScriptEngine::QtOwnership)),
  can be used when setting the qObject() of an QObjectInterface
  as parent of the qobject-derived wrapper. If the QObject goes
  out of scope while running the script, the script object
  will stop working.

A conversion cast to QScriptValue can then be provided.

How to wrap functions:

Most functions can then be implemented as slots, property-like
things as such.

The other functions have to be implemented via script-callbacks.
(Parameter checking required).

The templates in here can help in writing the wrapper
objects. For examples, see

src/plugins/core/scriptmanager/qworkbench_wrapper.h