Commits

Yosuke Onoue committed 7c58046

add caml_callback2, 3

Comments (0)

Files changed (2)

         self.lib.caml_startup(args)
         self.lib.caml_named_value.restype = ctypes.POINTER(ctypes.c_long)
         self.lib.caml_callback.restype = ctypes.c_long
+        self.lib.caml_callback2.restype = ctypes.c_long
+        self.lib.caml_callback3.restype = ctypes.c_long
         self.lib.caml_alloc.restype = ctypes.c_long
         #self.lib.caml_Double_val.restype = ctypes.c_double
 
     def caml_named_value(self, name):
         return self.lib.caml_named_value(ctypes.c_char_p(name)).contents
 
-    def caml_callback(self, closure, arg):
-        return ctypes.c_long(self.lib.caml_callback(closure, arg))
+    def caml_callback(self, *args):
+        l = len(args)
+        if l == 2:
+            return ctypes.c_long(self.lib.caml_callback(*args))
+        elif l == 3:
+            return ctypes.c_long(self.lib.caml_callback2(*args))
+        elif l == 4:
+            return ctypes.c_long(self.lib.caml_callback3(*args))
+        else:
+            # TODO
+            raise NotImplementedError()
 
     def caml_alloc(self, size, tag):
         return ctypes.c_long(self.lib.caml_alloc(size, tag))
 
     def is_long(self, x):
         return (x.value & 1) != 0
-    
+
     def is_block(self, x):
         return (x.value & 1) == 0
-    
+
     def val_long(self, x):
         return (x << 1) + 1
-    
+
     def long_val(self, x):
         return x.value >> 1
-    
+
     def val_int(self, x):
         return self.val_long(x)
-    
+
     def int_val(self, x):
-        return self.long_val(x)
+        return ctypes.c_int(self.long_val(x))
 
     def store_double_val(self, v, d):
         ctypes.c_double.from_address(v.value).value = d
 from setuptools import setup
 
-setup(name='ocamltypes',
+setup(name='otypes',
       version='0.1.0',
       author='Yosuke ONOUE',
       author_email='onoue@likr-lab.com',