Skip to content

Commit

Permalink
Add include info to c-binding's struct
Browse files Browse the repository at this point in the history
  • Loading branch information
sol-vin authored Nov 14, 2024
1 parent 815d88c commit 5ec0b66
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/syntax_and_semantics/c_bindings/struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ lib C
end
```

Structs that are defined inside a `lib` can be included as modules internally in other `lib` defined structs, for example:

```crystal
lib Lib
struct Foo
x : Int32
y : Int16
end
struct Bar
include Foo
z : Int8
end
end
Lib::Bar.new # => Lib::Bar(@x=0, @y=0, @z=0)
```

To create an instance of a struct use `new`:

```crystal
Expand Down

0 comments on commit 5ec0b66

Please sign in to comment.