Created
August 30, 2012 23:39
-
-
Save tshirtman/3545268 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| cdef class GenericNativeWrapper(object): | |
| """ | |
| This class is to be used to register python method as methods of | |
| JavaObjects using RegisterNatives | |
| """ | |
| cdef JNIEnv* j_env | |
| cdef args | |
| def __cinit__(self, j_env, definition, callback): | |
| self.j_env = NULL | |
| def __init__(self, j_env, definition, callback): | |
| self.callback = callback | |
| self.definitions = parse_definition(definition)[1] | |
| cdef void call_void(self, ...): | |
| cdef va_list j_args | |
| cdef int n | |
| cdef void* l | |
| args = [] | |
| va_start(j_args, <void*>self) | |
| for d in self.definitions: | |
| if d == 'Z': | |
| args.append(<bint>va_arg(j_args, bool_type)) | |
| elif d == 'B': | |
| args.append(<char>va_arg(j_args, char_type)) | |
| elif d == 'C': | |
| args.append(<char>va_arg(j_args, byte_type)) | |
| elif d == 'S': | |
| args.append(<short>va_arg(j_args, short_type)) | |
| elif d == 'I': | |
| args.append(<int>va_arg(j_args, int_type)) | |
| elif d == 'J': | |
| args.append(<long>va_arg(j_args, long_type)) | |
| elif d == 'F': | |
| args.append(<float>va_arg(j_args, float_type)) | |
| elif d == 'D': | |
| args.append(<double>va_arg(j_args, double_type)) | |
| else: # == L, java object | |
| l = <void*>va_arg(j_args, pointer_type) | |
| args.append(convert_jobject_to_python(self.j_env, d, l)) | |
| va_end(j_args) | |
| self.callback(*args) | |
| # XXX define call_int/call_bool/call_char/... and friends on the | |
| # same model, and "array of" variants | |
| cdef int call_int(self, ...): | |
| pass | |
| cdef int* call_int_a(self, ...): | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment