omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    ObjC handling for c functions

    Pythonista
    1
    1
    1367
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scj643
      scj643 last edited by

      This code is useful for handling c functions that should return ObjCInstances
      https://github.com/scj643/objc_tools/blob/master/objc_tools/c/objc_handler.py

      from objc_util import ObjCInstance, c_void_p
      
      def chandle(result, func, args):
          '''chandle
          Handles c_void_p to objc type
          use as a errcheck for a ctypes function
          >>> cfunc.restype = c_void_p
          >>> cfunc.errcheck = chandle
          '''
          if isinstance(result, (c_void_p, int)) and result:
              return ObjCInstance(result)
              
              
      if __name__ == '__main__':
          from objc_util import *
          from objc_util import c
          MRMediaRemoteCopyPickableRoutes = c.MRMediaRemoteCopyPickableRoutes
          MRMediaRemoteCopyPickableRoutes.restype = c_void_p
          MRMediaRemoteCopyPickableRoutes.errcheck = chandle
          t=MRMediaRemoteCopyPickableRoutes()```
      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Powered by NodeBB Forums | Contributors