diff options
author | Juan M Gómez <info@jmgomez.me> | 2023-05-08 16:04:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-08 17:04:27 +0200 |
commit | e45eb39ef7c194ee16a9fd3c2d08997f62c44375 (patch) | |
tree | f4d70dedd5e0d0df9d921b126a3323ae6e09d1ff /doc | |
parent | 4533e894ad0e113c6057d336290d2c903383e406 (diff) | |
download | Nim-e45eb39ef7c194ee16a9fd3c2d08997f62c44375.tar.gz |
documents codegendecl for object types (#21811)
Diffstat (limited to 'doc')
-rw-r--r-- | doc/manual.md | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/doc/manual.md b/doc/manual.md index cb2509bd2..93f13f818 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -8072,8 +8072,8 @@ CodegenDecl pragma ------------------ The `codegenDecl` pragma can be used to directly influence Nim's code -generator. It receives a format string that determines how the variable -or proc is declared in the generated code. +generator. It receives a format string that determines how the variable, +proc or object type is declared in the generated code. For variables, $1 in the format string represents the type of the variable, $2 is the name of the variable, and each appearance of $# represents $1/$2 @@ -8108,7 +8108,30 @@ will generate this code: ```c __interrupt void myinterrupt() ``` + +For object types, the $1 represents the name of the object type, $2 is the list of +fields and $3 is the base type. +```nim + +const strTemplate = """ + struct $1 { + $2 + }; +""" +type Foo {.codegenDecl:strTemplate.} = object + a, b: int +``` + +will generate this code: + + +```c +struct Foo { + NI a; + NI b; +}; +``` `cppNonPod` pragma ------------------ |