webgpu-headers: C Blocks API
C blocks are a more convenient way of handling callbacks. They automatically capture the relevant variables from the enclosing scope.
This:
WGPU_EXPORT void wgpuAdapterRequestDevice(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceCallback callback, void * userdata);
could turn into this:
WGPU_EXPORT void wgpuAdapterRequestDevice(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceCallback callback, void * userdata);
#if defined(__BLOCKS__)
WGPU_EXPORT void wgpuAdapterRequestDeviceWithBlock(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor, void (^callback)(WGPURequestDeviceStatus status, WGPUDevice device, char const * message))
#endif
(Of course, typedefs could make this more readable.)
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 16
One approach is to cast a pointer to the block to
void*and use a fixed function that converts thevoid*back to a block before calling it.