mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 16:57:35 +02:00
Update foreign.md
This commit is contained in:
parent
1d57b73861
commit
5b886b19e6
1 changed files with 29 additions and 27 deletions
|
@ -4,22 +4,10 @@ The `(cyclone foreign)` provides a convenient interface for integrating with C c
|
||||||
|
|
||||||
# Overview
|
# Overview
|
||||||
|
|
||||||
- [`c-define-type`(#c-define-type)
|
|
||||||
- [`c-code`](#c-code)
|
- [`c-code`](#c-code)
|
||||||
- [`c-value`](#c-value)
|
- [`c-value`](#c-value)
|
||||||
- [`c-define`](#c-define)
|
- [`c-define`](#c-define)
|
||||||
|
- [`c-define-type`](#c-define-type)
|
||||||
## c-define-type
|
|
||||||
|
|
||||||
*Syntax*
|
|
||||||
|
|
||||||
(c-define-type NAME TYPE (ARG-CONVERT (RET-CONVERT)))
|
|
||||||
|
|
||||||
Define a custom type with symbol `NAME` that is an alias of type `TYPE`. It is also possible to specify conversion functions `ARG-CONVERT` and `RET-CONVERT` to convert to/from this custom type.
|
|
||||||
|
|
||||||
EG, to define a type that consists of integers in Scheme and strings in C:
|
|
||||||
|
|
||||||
(c-define-type string-as-integer string number->string string->number)
|
|
||||||
|
|
||||||
## c-code
|
## c-code
|
||||||
|
|
||||||
|
@ -51,20 +39,34 @@ For example, to define a function that calls `strlen`:
|
||||||
|
|
||||||
Note that these definitions are introduced at the top-level.
|
Note that these definitions are introduced at the top-level.
|
||||||
|
|
||||||
|
## c-define-type
|
||||||
|
|
||||||
|
*Syntax*
|
||||||
|
|
||||||
|
(c-define-type NAME TYPE (ARG-CONVERT (RET-CONVERT)))
|
||||||
|
|
||||||
|
Define a custom type with symbol `NAME` that is an alias of type `TYPE`. It is also possible to specify conversion functions `ARG-CONVERT` and `RET-CONVERT` to convert to/from this custom type.
|
||||||
|
|
||||||
|
EG, to define a type that consists of integers in Scheme and strings in C:
|
||||||
|
|
||||||
|
(c-define-type string-as-integer string number->string string->number)
|
||||||
|
|
||||||
|
|
||||||
# Type Specifiers
|
# Type Specifiers
|
||||||
|
|
||||||
TODO: list of type specifiers
|
The following built-in specifiers may be used as a `TYPE` for forms in this module.
|
||||||
built-in types
|
|
||||||
Scheme | C
|
Scheme | C
|
||||||
int | int
|
------ | -
|
||||||
integer | int
|
`int` | `int`
|
||||||
bool | int
|
`integer` | `int`
|
||||||
char | int
|
`bool` | `int`
|
||||||
string | char *
|
`char` | `int`
|
||||||
symbol | const char *
|
`string` | `char *`
|
||||||
bytevector | char *
|
`symbol` | `const char *`
|
||||||
float | double
|
`bytevector` | `char *`
|
||||||
double | double
|
`float` | `double`
|
||||||
bignum | mp_int
|
`double` | `double`
|
||||||
opaque | void *
|
`bignum` | `mp_int`
|
||||||
|
`opaque` | `void *`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue