I'm mocking about with plt-scheme's ffi and I have a C-function that returns a char ** (array of strings). If I declare my function as (_fun _pointer -> _pointer)
, how do I convert the result to a list of strings in scheme?
我正在用plt-scheme的ffi嘲笑我有一个C函数返回一个char **(字符串数组)。如果我将我的函数声明为(_fun _pointer - > _pointer),如何将结果转换为scheme中的字符串列表?
Here are the relevant C-declarations:
以下是相关的C声明:
typedef char **MYSQL_ROW; /* return data as array of strings */
// ...
MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
3 个解决方案
#1
1
I think that what you want is the cvector:
我认为你想要的是cvector:
http://docs.plt-scheme.org/foreign/Derived_Utilities.html#(part._foreign~3acvector)
A cvector of _string/utf-8 or whichever encoding you need seems reasanable.
_string / utf-8的cvector或者你需要的任何编码似乎都是可以接受的。
But that's from a quick survey of the docs - I haven't tried this myself. Please let me know if it works!
但这是对文档的快速调查 - 我自己没有尝试过。如果有效,请告诉我!
#2
0
I know it's not exactly what you are looking for, but it might help a little bit. I've done some work on a basic Gambit Scheme FFI for MySQL. I don't know how PLT Scheme and Gambit differ in terms of their FFI implementation (I'd venture with "quite a bit") but maybe you can get something out of it:
我知道这不是你想要的,但它可能会有所帮助。我已经完成了一些关于MySQL的基本Gambit Scheme FFI的工作。我不知道PLT Scheme和Gambit在FFI实施方面有何不同(我冒险“相当多”)但也许你可以从中得到一些东西:
http://bunny.jonnay.net/zengarden/trunk/lib/mysql/mysql-ffi.scm
#3
0
Aha, I figured it out myself.
啊哈,我自己想通了。
I have to use the _cpointer
procedure, described at the page that mike linked to:
我必须使用_cpointer过程,在mike链接到的页面中描述:
(_fun _pointer -> (_cpointer/null 'mysql-row (make-ctype _pointer #f #f)))
It also seems that someone already beat me to creating a ffi to mysqlclient. Not to worry; My main goal is understanding the ffi api, and it's going forward.
似乎有人已经打败我为mysqlclient创建一个ffi。不用担心;我的主要目标是了解ffi api,并且它正在向前发展。
#1
1
I think that what you want is the cvector:
我认为你想要的是cvector:
http://docs.plt-scheme.org/foreign/Derived_Utilities.html#(part._foreign~3acvector)
A cvector of _string/utf-8 or whichever encoding you need seems reasanable.
_string / utf-8的cvector或者你需要的任何编码似乎都是可以接受的。
But that's from a quick survey of the docs - I haven't tried this myself. Please let me know if it works!
但这是对文档的快速调查 - 我自己没有尝试过。如果有效,请告诉我!
#2
0
I know it's not exactly what you are looking for, but it might help a little bit. I've done some work on a basic Gambit Scheme FFI for MySQL. I don't know how PLT Scheme and Gambit differ in terms of their FFI implementation (I'd venture with "quite a bit") but maybe you can get something out of it:
我知道这不是你想要的,但它可能会有所帮助。我已经完成了一些关于MySQL的基本Gambit Scheme FFI的工作。我不知道PLT Scheme和Gambit在FFI实施方面有何不同(我冒险“相当多”)但也许你可以从中得到一些东西:
http://bunny.jonnay.net/zengarden/trunk/lib/mysql/mysql-ffi.scm
#3
0
Aha, I figured it out myself.
啊哈,我自己想通了。
I have to use the _cpointer
procedure, described at the page that mike linked to:
我必须使用_cpointer过程,在mike链接到的页面中描述:
(_fun _pointer -> (_cpointer/null 'mysql-row (make-ctype _pointer #f #f)))
It also seems that someone already beat me to creating a ffi to mysqlclient. Not to worry; My main goal is understanding the ffi api, and it's going forward.
似乎有人已经打败我为mysqlclient创建一个ffi。不用担心;我的主要目标是了解ffi api,并且它正在向前发展。