Implement attrs: extendedattribute and extraheader
This commit is contained in:
parent
d64f4d1c62
commit
014d4ea4df
7 changed files with 283 additions and 45 deletions
28
README.md
28
README.md
|
|
@ -68,7 +68,9 @@ capnp compile -o ./capnpc-c myschema.capnp
|
|||
|
||||
`capnp` generates a C struct that corresponds to each capn proto struct, along with read/write functions that convert to/from capn proto form.
|
||||
|
||||
If you want accessor functions for struct members, use attribute `fieldgetset` in your `.capnp` file as follows:
|
||||
#### fieldgetset
|
||||
|
||||
If you want accessor functions for struct members, use the attribute `fieldgetset` in your `.capnp` file as follows:
|
||||
|
||||
```capnp
|
||||
using C = import "${c-capnproto}/compiler/c.capnp";
|
||||
|
|
@ -78,6 +80,30 @@ $C.fieldgetset;
|
|||
struct MyStruct {}
|
||||
```
|
||||
|
||||
#### extraheader
|
||||
|
||||
If you want to add `#include <...>` or any other preprocessor statements in your generated C file, use the attribute `extraheader` in your `.capnp` file as follows:
|
||||
|
||||
```capnp
|
||||
using C = import "${c-capnproto}/compiler/c.capnp";
|
||||
|
||||
$C.extraheader("include <stdio.h>");
|
||||
|
||||
struct MyStruct {}
|
||||
```
|
||||
|
||||
#### extendedattribute
|
||||
|
||||
If you want to add an `__declspec(dllexport)` or some other extended attribute to your generated C functions and structs, use the attribute `extendedattribute` in your `.capnp` file as follows:
|
||||
|
||||
```capnp
|
||||
using C = import "${c-capnproto}/compiler/c.capnp";
|
||||
|
||||
$C.extendedattribute("__declspec(dllexport)");
|
||||
|
||||
struct MyStruct {}
|
||||
```
|
||||
|
||||
### Example C code
|
||||
|
||||
See the unit tests in [`tests/example-test.cpp`](tests/example-test.cpp).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue