Пример #1
0
def register_callback(name, c_type, callback):
    """Called at initialisation time to register a single callback."""
    f = ffi.cast(ffi_to_string(c_type), callback)
    if is_py3:
        # Wrap the function up to auto-encode to bytes (ffi requires this in py3)
        # TODO(pebers): this is not exactly beautiful, can we find a better way of handling it?
        globals()[ffi_to_string(name)] = lambda *args: f(
            *[ffi_from_string(arg) if isinstance(arg, str) else arg for arg in args])
    else:
        globals()[ffi_to_string(name)] = f
    return 1  # used to detect success (must be nonzero)
Пример #2
0
def register_callback(name, c_type, callback):
    """Called at initialisation time to register a single callback."""
    globals()[ffi_to_string(name)] = ffi.cast(ffi_to_string(c_type), callback)