File: slots.rst.txt

package info (click to toggle)
pygame 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 42,624 kB
  • sloc: ansic: 66,926; python: 48,742; javascript: 1,153; objc: 224; sh: 121; makefile: 59; cpp: 25
file content (30 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
.. include:: ../common.txt

.. highlight:: c

************************************************************************
Slots and c_api - Making functions and data available from other modules
************************************************************************


One example is pg_RGBAFromObj where the implementation is defined in base.c, and also exported in base.c (and _pygame.h).

base.c has this exposing the pg_RGBAFromObj function to the `c_api` structure:

    c_api[12] = pg_RGBAFromObj;


Then in src_c/include/_pygame.h there is an

	#define pg_RGBAFromObj.

Also in _pygame.h, it needs to define the number of slots the base module uses. This is PYGAMEAPI_BASE_NUMSLOTS. So if you were adding another function, you need to increment this PYGAMEAPI_BASE_NUMSLOTS number.

Then to use the pg_RGBAFromObj in other files,

1) include the "pygame.h" file,
2) they have to make sure base is imported with:

	import_pygame_base();

Examples that use pg_RGBAFromObj are: _freetype.c, color.c, gfxdraw.c, and surface.c.