A C function pointer cannot be formed from a local function that captures context on Swift Package

Ah! Well, if your goal is for newMessageHandler to capture context, then you will have to put it in a Swift type, rather than a C type. Go back to your old version with the UserData class and Unmanaged, and make sure to annotate cHandler with @convention(c).