XS如何将C的数据结构返回给Perl代码

18 views
Skip to first unread message

twcai

unread,
Oct 16, 2012, 3:35:45 AM10/16/12
to perl...@googlegroups.com
在XS中,像test_struct(定义如下)这样用户定义的结构体,要怎么样以一个Hash的形式返回给Perl代码呢?
浏览了下
perlxstypemap,不过因为时间略急,没能找到答案,只好同时在线等大牛解惑。

typedef enum TEST_BOOLEAN {

    TEST_FALSE,
    TEST_TRUE
}TEST_BOOLEAN;
 
typedef struct test_struct {
    int id;
    double radio;
    const char *name;
    TEST_BOOLEAN exist;
}test_struct;
 
extern test_struct *foo (int id, double radio, const char *name);

greencow

unread,
Oct 16, 2012, 12:00:38 PM10/16/12
to perl...@googlegroups.com
可以返回一个ptr或ptrobj

twcai

unread,
Oct 16, 2012, 12:16:14 PM10/16/12
to perl...@googlegroups.com
谢谢。不过ptr貌似只返回一个内存地址,怎么样用perl去获取这个内存地址中的内容呢?

greencow

unread,
Oct 17, 2012, 10:15:12 AM10/17/12
to perl...@googlegroups.com
You need to create one XS function to operate the data. Don't worry. There's lots of rumor about how ugly XS is, though actually XS is the most clean and powerful way to extend a scripting language.
Reply all
Reply to author
Forward
0 new messages