Skip to content

Migrating from OVR C API to Python

Christopher Bruns edited this page Oct 24, 2015 · 12 revisions

Identifier prefixes vs. module namespace

Many function names, constants, and type names in the C OVR API begin with prefixes such as "ovr", "OVR_", or "ovr_". These prefixes are removed in the Python API, because all of these identifiers are in the python "ovr" module namespace.

For example, the C code

OVR_KEY_IPD

would become in python

ovr.KEY_IPD

In the Python API, identifiers are changed like so:

  1. All OVR API identifiers are the "ovr" module namespace
  2. Prefix "ovr", "OVR_", or "ovr_" is stripped off; OVR_KEY_IPD becomes ovr.KEY_IPD
  3. Type names begin with a capital letter ovrTrackingState becomes ovr.TrackingState
  4. function names begin with a lower case letter ovr_Shutdown() becomes ovr.shutdown()
  5. macros retain their capitalization OVR_KEY_IPD becomes ovr.KEY_IPD
  6. enum values retain their capitialization ovrTrackingCap_Orientation becomes ovr.TrackingCap_Orientation

Return values vs. exceptions

Many OVR functions in the C API return a value of type ovrResult. The corresponding functions in the Python API do not return an ovrResult, but rather raise an exception, in the case where ovrResult was not OVR_SUCCESS.

For example, the C code

ovrResult result = ovr_Initialize(nullptr);
if (OVR_FAILURE(result))
    return;

becomes

try:
    ovr.initialize(None)
except:
    return
Clone this wiki locally