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.


    Listing all methods in an ObjCClass

    Pythonista
    4
    10
    6424
    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.
    • polymerchm
      polymerchm last edited by

      Somewhere, one of the Objc_util gurus posted a script to display all methods of a ObjectiveC class in a TextView. I have, of course, lost it.

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        objc_browser in my objc_hacks repo shows a tableview of all known classes. tapping a class shows all instance methods of that class(and copys the name to the clipboard). tapping a method copies the method name to the clipboard, and also installs a logger to all calls to that method in order to get into on arguments.... I don't recommend doing that.

        also, i think i have a print_objc .py file which lets you print all methods of a class, showing which are inherited vs specific to the class.

        1 Reply Last reply Reply Quote 0
        • polymerchm
          polymerchm last edited by

          They're not real happy with Pythonista 3, or the beta. I think the underlying implementation of .startswith() is re based and not real happy with bytestrings.

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            objc_browser should work in both interpreters. i usually run it in 3.x. it requires swizzlelog, and swizzle, though those could be removed if you just want to browse.

            print_objc.print_methods works with the 2.7 interpreter.... though the latest beta seems to have broken the shebang controlling interpreter... long press to run in 2.7, and of course switch console interpreter in the corner. probably i should just make the browser highlight cells based on whether it is a class method, inherited instance method, or specialized instance method.

            wolf71 1 Reply Last reply Reply Quote 0
            • wolf71
              wolf71 @JonB last edited by

              @JonB

              1. Can add function list. list all objc c function?
              2. Can browser objc const's value ?
              1 Reply Last reply Reply Quote 0
              • JonB
                JonB last edited by JonB

                Not sure what you mean by all objc functions... if you mean the c dll symbols, i am not sure if that is possible, plus there are so damn many of them i am not aure how useful it would be.

                Likewise with consts...

                1 Reply Last reply Reply Quote 0
                • dgelessus
                  dgelessus last edited by

                  What JonB said. The Objective-C runtime only knows about Objective-C classes and objects. Functions that don't belong to a class are normal C functions, and there is no good way to list all C functions declared in a library. You can only use a function if you know its name and set its restype and argtypes.

                  The NSString constants used in various frameworks are similar, there is no way to list all of them, but you can get them by name using ctypes.c_void_p.in_dll.

                  Integer constants (defined with enum or #define in C) are replaced with normal integers by the compiler. There is no way to get an enum or #define constant by its name using ctypes.

                  wolf71 JonB 2 Replies Last reply Reply Quote 0
                  • wolf71
                    wolf71 @dgelessus last edited by

                    Thanks @dgelessus @JonB

                    1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB @dgelessus last edited by

                      @dgelessus In retrosepct, while it is not usually possible to list symbols in a dll, here we actually have a static library. So the symbol table must be present....

                      sure enough,

                      import sys
                      f=open('sys.executable','rb')
                      while True:
                         s=f.read(10000).decode('latin1').replace('\x00','')
                         if s.find('objc_msgSend') >0:
                            print(f.tell())
                            break
                      

                      stops an a chunk of symbol table.
                      Looks like a regex looking for @_ and ending with \x90 should capture all symbols... looks like tonights project...

                      1 Reply Last reply Reply Quote 0
                      • JonB
                        JonB last edited by

                        import sys,re, mmap
                        
                        with open(sys.executable,'rb') as f:
                        	m=mmap.mmap(f.fileno(),0, access=mmap.ACCESS_READ)
                        	symbols=re.findall(b'@_(\w*)',m)
                        

                        obviously not a complete list, but this gives me about 1500 symbols.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors