libretro.api¶
Python equivalents of the C data structures defined in libretro.h.
Almost all types in this module are ctypes-based wrappers around
their equivalents in libretro.h.
Although these types are primarily meant to be used with
the drivers in libretro.drivers,
they do not depend on any driver protocols or implementations.
They follow these conventions unless otherwise stated:
Naming¶
All function pointer types and
Structuresubclasses are named exactly the same as their C counterparts.All explicit
enumtypes are givenCamelCasenames that match the name of their C counterparts with the commonRETRO_prefix removed.All groups of related
#defineconstants are givenCamelCasetype names derived from their common prefix in C.All enum values (both explicit and
#defines ) are named inALL_CAPS_SNAKE_CASE, with their common prefix removed.
Type Conversions¶
This module’s types rely heavily on the conversions defined by ctypes.
The linked documentation provides details, but in a nutshell:
- Python objects are implicitly converted to equivalent C data types when:
Assigned to a
Structurefield, or;Stored as an element in an appropriately-typed
Array, or;Assigned as the target of a
_Pointer(or equivalentTypedPointer), or;Passed as an argument to a C function defined with
CFUNCTYPE()(or the equivalentTypedFunctionPointer).
- C data types are implicitly converted to equivalent
ctypesobjects or Python primitives when: Accessed as a field of a
Structure, or;Accessed as an element of an
Array, or;Accessed as the target of a
_Pointer(or equivalentTypedPointer), or;Returned as the result of a C function defined with
CFUNCTYPE()(or the equivalentTypedFunctionPointer).
- C data types are implicitly converted to equivalent
Python classes that implement
AsParametercan be implicitly converted to C data types when passed toCFUNCTYPE()-defined functions.C integers are converted to Python
ints regardless of their size or signedness.Python
ints are masked to fit the size and signedness of the target C integer type when converted to C.C floating-point types are converted to and from Python
floats.Python
bytesobjects are converted to and fromNULL-terminated char*s.NULLC pointers of any type are converted to and fromNone.C bools are converted to and from Python
bools.C void* pointers are converted to and from
ints.Subclasses of any
ctypesprimitive are not implicitly converted to Python primitives.
See also
libretro.ctypesVarious
ctypes-compatible types and utility functions.
Additional Methods¶
copy.deepcopy()¶
Unless otherwise noted, all structs can be copied with copy.deepcopy();
the struct itself and its fields (including strings and buffers) are all deep-copied.
For example:
import copy
from libretro.api import retro_controller_description
desc = retro_controller_description(b'Game Pad', 5)
desc_copy = copy.deepcopy(desc)
assert desc == desc_copy
desc.desc = b'Another Game Pad'
assert desc != desc_copy
Collection Protocols¶
Where applicable, structs that logically represent arrays of items (e.g. retro_controller_info)
implement collections.abc.Sequence to allow indexing and iteration over the items,
plus __setitem__ to update values. For example:
from libretro.api import retro_controller_info
info = retro_controller_info()
info.num_descriptions = 2
info.descriptions[0] = retro_controller_description(b'Game Pad', 5)
info.descriptions[1] = retro_controller_description(b'Analog Stick', 2)
assert len(info) == 2
assert info[0].desc == b'Game Pad'
assert info[1].desc == b'Analog Stick'
See also
libretro.drivers for driver protocols that use these types.
Modules
Audio callback and sample rendering types. |
|
Types to describe the parameters of a core's rendered audio and video. |
|
Interface and types for providing video input to a |
|
Types that define the content that can be (or has been) loaded by a |
|
Types and callbacks for using the emulated system's disk drives, if any. |
|
Types for interfacing between a |
|
Input device definitions, state representations, and callbacks. |
|
Types for allowing |
|
Geographic location service interface types. |
|
Types for allowing |
|
Types that describe the address space of the |
|
Types that allow |
|
Microphone audio capture interface types. |
|
MIDI input/output interface types. |
|
Network packet exchange interface types for multiplayer. |
|
Core option definitions, values, categories, and internationalization. |
|
Performance counter and SIMD feature detection types. |
|
Types for exposing a frontend's power status to a |
|
Types for retrieving core functions beyond the standard |
|
Rumble (force feedback) interface types. |
|
Types that define serialization quirks and savestate contexts. |
|
Types for providing sensor input to cores. |
|
Types for managing the rate at which the |
|
User interface language types and constants. |
|
Virtual filesystem (VFS) interface types and callbacks. |
|
Video callback and rendering types. |