Created
August 28, 2012 00:20
-
-
Save tshirtman/3493734 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 | |
| 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 call(self, ...): | |
| # this method will convert the args passed to it and call the callback | |
| # with the arguments all converted | |
| cdef va_list j_args | |
| cdef void* n | |
| cdef int i | |
| va_start(j_args, <void*>n) | |
| args = [] | |
| while n != NULL: | |
| args.append(convert_jobject_to_python(self.j_env, self.definitions[i], n)) | |
| n = <void*>va_arg(j_args, int_type) | |
| va_end(j_args) | |
| self.callback(*args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment