blueloveTH 1 năm trước cách đây
mục cha
commit
6a137c4e0d
2 tập tin đã thay đổi với 17 bổ sung2 xóa
  1. 13 0
      docs/C-API/introduction.md
  2. 4 2
      include/pocketpy/pocketpy.h

+ 13 - 0
docs/C-API/introduction.md

@@ -32,6 +32,19 @@ Also, `py_retval()` is a special register that is used to store the return value
 Registers are shared so they could be overwritten easily.
 If you want to store python objects across function calls, you should store them into the stack via `py_push()` and `py_pop()`.
 
+## Data Types
+
+You can do conversions between C types and python objects using the following functions:
+
+| C type              | Python type | C to Python     | Python to C                      |
+| ------------------- | ----------- | --------------- | -------------------------------- |
+| char,short,int,long | int         | `py_newint()`   | `py_toint()`                     |
+| float,double        | float       | `py_newfloat()` | `py_tofloat()`, `py_castfloat()` |
+| bool                | bool        | `py_newbool()`  | `py_tobool()`                    |
+| const char*         | str         | `py_newstr()`   | `py_tostr()`                     |
+| void*,intptr_t      | int         | `py_newint()`   | `(void*)py_toint()`              |
+
+---
 
 ### `PY_RAISE` macro
 

+ 4 - 2
include/pocketpy/pocketpy.h

@@ -459,8 +459,10 @@ PK_API py_StackRef py_pushtmp();
 /// If return true:  `[self] -> [unbound, self]`.
 /// If return false: `[self] -> [self]` (no change).
 PK_API bool py_pushmethod(py_Name name);
-/// Call a callable object.
-/// Assume `argc + kwargc` arguments are already pushed to the stack.
+/// Call a callable object via pocketpy's calling convention.
+/// You need to prepare the stack using this form: `callable, self/nil, arg1, arg2, ..., k1, v1, k2, v2, ...`
+/// `argc` is the number of positional arguments excluding `self`.
+/// `kwargc` is the number of keyword arguments, i.e. the number of key-value pairs.
 /// The result will be set to `py_retval()`.
 /// The stack size will be reduced by `argc + kwargc`.
 PK_API bool py_vectorcall(uint16_t argc, uint16_t kwargc) PY_RAISE PY_RETURN;