Created
July 9, 2018 15:14
-
-
Save jsbain/d1b10d812306a749335e052eb5e1af9e to your computer and use it in GitHub Desktop.
Untitled_200.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from objc_util import * | |
def foo_bar(_self,_cmd): | |
baz = 5 | |
return baz | |
foo_bar.encoding = 'l@:' | |
''' | |
first character is return type, then each argument, per encodings below. @ is objc object, : is selector. | |
type_encodings = {'c': c_byte, 'i': c_int, 's': c_short, 'l': c_int32, 'q': c_longlong, | |
'C': c_ubyte, 'I': c_uint, 'S': c_ushort, 'L': c_ulong, 'Q': c_ulonglong, | |
'f': c_float, 'd': c_double, 'B': c_bool, 'v': None, '*': c_char_p, | |
'@': c_void_p, '#': c_void_p, ':': c_void_p, | |
'{CGPoint}': CGPoint, '{CGSize}': CGSize, '{CGRect}': CGRect, '{CGVector}': CGVector, | |
'{CGAffineTransform}': CGAffineTransform, '{UIEdgeInsets}': UIEdgeInsets, '{_NSRange}': NSRange, | |
'?': c_void_p, '@?': c_void_p | |
''' | |
#. encoding is mandatory. optional, you can also set restype and argtypes, but do it before you create the class. if either is omitted, both fallback to what is in encoding. | |
#foo_bar.argtypes=[] | |
#foo_bar.restype=c_int32 | |
foo=create_objc_class('foo',methods=[foo_bar]) | |
foo = foo.alloc().init() | |
print('out {}'.format(foo.bar())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment