Skip to content

Instantly share code, notes, and snippets.

@taichi
Created October 31, 2010 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taichi/656581 to your computer and use it in GitHub Desktop.
Save taichi/656581 to your computer and use it in GitHub Desktop.
cython
/* callback.h START*/
#ifndef _CALLBACK_H_
#define _CALLBACK_H_
typedef int (*op)(int,int);
int binary_op(int a, int b, op func);
#endif
/* callback.h END*/
/* callback.c START */
#include "callback.h"
int binary_op(int a, int b, op func) {
return (func)(a,b);
}
/* callback.c END */
/* cython2.pyx START */
cdef extern from "callback.h":
ctypedef int (*op)(int,int)
int binary_op(int a, int b, op func)
cdef int callback(int a, int b):
return bop_callback(a,b)
cdef bop_callback
def bop(a,b,func):
global bop_callback
bop_callback = func
print(bop_callback(a,b))
print('aaaa')
return binary_op(a,b,callback)
/* cython2.pyx END */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment