From 6a137c4e0dd5bdd517f9223523b23b421582b1d4 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 8 Oct 2024 11:55:26 +0800 Subject: [PATCH] fix docs --- docs/C-API/introduction.md | 13 +++++++++++++ include/pocketpy/pocketpy.h | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/C-API/introduction.md b/docs/C-API/introduction.md index 36183ebf..be744d81 100644 --- a/docs/C-API/introduction.md +++ b/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 diff --git a/include/pocketpy/pocketpy.h b/include/pocketpy/pocketpy.h index 5db4762c..02e65a43 100644 --- a/include/pocketpy/pocketpy.h +++ b/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;