在Crystal FFI中,如何访问C库中的类型?

问题描述

我正在做的任务是为Crystal的SQLite绑定添加对the create_function interface的支持:https://github.com/crystal-lang/crystal-sqlite3/issues/61

要访问用户定义函数的参数,我需要访问sqlite3_value类型的C样式数组(即,指向连续实例的指针),如果我没记错的话,它需要知道类型的大小。但是据我所知,还没有办法将Crystal类型声明为C库中定义的类型的别名。

解决方法

因为它是一个指针,所以不,您不必知道其布局。对于opaque pointers,此模式在Crystal中很常见:

type Sqlite3Context = Void*
type Sqlite3Value = Void*

fun sqlite3_create_function(
  [...]
  xFunc : (Sqlite3Context,Int,Sqlite3Value*) ->,[...]
)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...