您尚未登录。

楼主 # 2022-04-02 16:22:39

jtp108
会员
注册时间: 2022-03-20
已发帖子: 2
积分: 7

C模块接口中的指针型出参如何返给py

比如,C模块中有一个接口:short dc_cpuapdu_hex(HANDLE icdev, unsigned char slen, char *sendbuffer, unsigned char *rlen, char *databuffer);
其中,rlen和databuffer是出参,
请问,这两个参数如何返给py层?
麻烦给个C模块实现和py层调用的例子,谢谢!

离线

#1 2022-04-02 16:41:31

lyon1998
Moderator
注册时间: 2021-12-01
已发帖子: 108
积分: 55

Re: C模块接口中的指针型出参如何返给py

目前 pikascript 不支持多值返回,如果需要返回多个值,可以使用对象的属性 api,将返回值保存进对象的属性中,再依次取出。
例如:
pika 的C模块py中:

# python
class Test(TinyObj):
    def test(a:int, b:float):
        pass

pika 的C模块.c 中:

/* C */
void Test_test(PikaObj* self, int a, float b){
    int res1;
    float res2;

    /* do something */

    obj_setInt(self, "c", res1);
    obj_setFloat(self,"d", res2);
}

Python 调用中:

mytest = Test()
a = 1
b = 2
mytest.test(a,b)
res1 = mytest.c
res2 = mytest.d

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn