PySide Shiboken Sequence Protocol: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Add "cleanup" tag)
(Rename category "LanguageBindings::PySide" -> "PySide")
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}


[[Category:LanguageBindings::PySide]]


= PySide Shiboken Sequence Protocol =
[[Category:PySide]]


Support for the sequence protocol is achieved adding functions with special names, this is done using the add-function tag.
Support for the sequence protocol is achieved adding functions with special names, this is done using the add-function tag.
Line 9: Line 7:
The special function names are:
The special function names are:


{|
{| class="wikitable"
!Function name
!Function name
!Parameters
!Parameters
Line 15: Line 13:
!CPython equivalent
!CPython equivalent
|-
|-
|__len__
|__len__
|PyObject* self
|PyObject* self
|Py_ssize_t
|Py_ssize_t
|PySequence_Size
|PySequence_Size
|-
|-
|__getitem__
|__getitem__
|PyObject* self, Py_ssize_t _i
|PyObject* self, Py_ssize_t _i
|PyObject*
|PyObject*
|PySequence_GetItem
|PySequence_GetItem
|-
|-
|__setitem__
|__setitem__
|PyObject* self, Py_ssize_t _i, PyObject* _value
|PyObject* self, Py_ssize_t _i, PyObject* _value
|int
|int
|PySequence_SetItem
|PySequence_SetItem
|-
|-
|__contains__
|__contains__
|PyObject* self, PyObject* _value
|PyObject* self, PyObject* _value
|int
|int
|PySequence_Contains
|PySequence_Contains
|-
|-
|__concat__
|__concat__
|PyObject* self, PyObject* _other
|PyObject* self, PyObject* _other
|PyObject*
|PyObject*

Latest revision as of 03:31, 5 June 2016


Support for the sequence protocol is achieved adding functions with special names, this is done using the add-function tag.

The special function names are:

Function name Parameters Return type CPython equivalent
__len__ PyObject* self Py_ssize_t PySequence_Size
__getitem__ PyObject* self, Py_ssize_t _i PyObject* PySequence_GetItem
__setitem__ PyObject* self, Py_ssize_t _i, PyObject* _value int PySequence_SetItem
__contains__ PyObject* self, PyObject* _value int PySequence_Contains
__concat__ PyObject* self, PyObject* _other PyObject* PySequence_Concat

You just need to inform the function name to the add-function tag, without any parameter or return type information, when you do it, Shiboken will create a C function with parameters and return type definied by the table above.

The function needs to follow the same semantics of the CPython equivalent function, the only way to do it is using the inject-code tag.