在 Crystal FFI 中,如何访问 C 库中的类型?
In Crystal FFI, how do I access a type in the C library?
我正在处理的任务是添加对 the create_function
interface to Crystal's SQLite binding: 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*) ->,
[...]
)
我正在处理的任务是添加对 the create_function
interface to Crystal's SQLite binding: 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*) ->,
[...]
)