Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add section about lib function visibility in macro #662

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/syntax_and_semantics/c_bindings/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ Attributes are used to pass flags to the linker to find external libraries:
* `@[Link(framework: "Cocoa")]` will pass `-framework Cocoa` to the linker (only useful in macOS).

Attributes can be omitted if the library is implicitly linked, as in the case of libc.

## Reflection

Lib functions are visible in the macro language anywhere in the program using the method [`TypeNode#methods`](https://crystal-lang.org/api/Crystal/Macros/TypeNode.html#methods%3AArrayLiteral%28Def%29-instance-method):

```crystal
lib LibFoo
fun foo
end

{{ LibFoo.methods }} # => [fun foo]
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
```