blueloveTH 1 năm trước cách đây
mục cha
commit
8de566f875
2 tập tin đã thay đổi với 9 bổ sung19 xóa
  1. 4 14
      include/pocketpy/pocketpy.h
  2. 5 5
      src/public/cast.c

+ 4 - 14
include/pocketpy/pocketpy.h

@@ -149,6 +149,7 @@ py_GlobalRef py_tpmagic(py_Type type, py_Name name);
 
 // new style decl-based bindings
 void py_bind(py_Ref obj, const char* sig, py_CFunction f);
+
 py_ObjectRef py_bind2(py_Ref obj,
                       const char* sig,
                       py_CFunction f,
@@ -156,20 +157,6 @@ py_ObjectRef py_bind2(py_Ref obj,
                       const char* docstring,
                       int slots);
 
-py_ObjectRef py_bind3(py_Ref obj,
-                      py_CFunction f,
-                      c11_sv name,
-                      c11_sv* args,
-                      int argc,
-                      c11_sv starred_arg,
-                      c11_sv* kwargs,
-                      int kwargc,
-                      py_Ref kwdefaults,  // a tuple contains default values
-                      c11_sv starred_kwarg,
-                      enum BindType bt,
-                      const char* docstring,
-                      int slots);
-
 // old style argc-based bindings
 void py_bindmethod(py_Type type, const char* name, py_CFunction f);
 void py_bindmethod2(py_Type type, const char* name, py_CFunction f, enum BindType bt);
@@ -381,6 +368,9 @@ bool py_tpcall(py_Type type, int argc, py_Ref argv);
 /// Check if the object is an instance of the given type.
 bool py_checktype(py_Ref self, py_Type type);
 
+/// Get the type of the object.
+py_Type py_typeof(py_Ref self);
+
 #define py_checkint(self) py_checktype(self, tp_int)
 #define py_checkfloat(self) py_checktype(self, tp_float)
 #define py_checkbool(self) py_checktype(self, tp_bool)

+ 5 - 5
src/public/cast.c

@@ -42,8 +42,8 @@ void* py_touserdata(py_Ref self) {
 bool py_istype(py_Ref self, py_Type type) { return self->type == type; }
 
 bool py_checktype(py_Ref self, py_Type type) {
-    if(self->type != type) {
-        return TypeError("expected %t, got %t", type, self->type);
-    }
-    return true;
-}
+    if(self->type == type) return true;
+    return TypeError("expected %t, got %t", type, self->type);
+}
+
+py_Type py_typeof(py_Ref self) { return self->type; }