From 158283ff4346a734903028ee01cb66530e82eb4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Sat, 7 Jan 2023 14:44:19 +0100 Subject: [PATCH 1/4] Add section about `lib` function visibility in macro --- docs/syntax_and_semantics/c_bindings/lib.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/syntax_and_semantics/c_bindings/lib.md b/docs/syntax_and_semantics/c_bindings/lib.md index 1cb1e91a6..527fd7715 100644 --- a/docs/syntax_and_semantics/c_bindings/lib.md +++ b/docs/syntax_and_semantics/c_bindings/lib.md @@ -17,3 +17,14 @@ 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. + +```crystal +lib LibFoo + fun foo +end +{% if LibFoo.methods %} # => [fun foo] +``` From 700710b4c12912959a004f3f3af1a26031185c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Sat, 7 Jan 2023 17:56:56 +0100 Subject: [PATCH 2/4] Update docs/syntax_and_semantics/c_bindings/lib.md Co-authored-by: George Dietrich --- docs/syntax_and_semantics/c_bindings/lib.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/syntax_and_semantics/c_bindings/lib.md b/docs/syntax_and_semantics/c_bindings/lib.md index 527fd7715..ef2837313 100644 --- a/docs/syntax_and_semantics/c_bindings/lib.md +++ b/docs/syntax_and_semantics/c_bindings/lib.md @@ -26,5 +26,5 @@ Lib functions are visible in the macro language anywhere in the program. lib LibFoo fun foo end -{% if LibFoo.methods %} # => [fun foo] +{{ LibFoo.methods }} # => [fun foo] ``` From 9b76af4040426284c0093f6479b3b1065a9f5048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Mon, 9 Jan 2023 17:52:44 +0100 Subject: [PATCH 3/4] Update docs/syntax_and_semantics/c_bindings/lib.md Co-authored-by: Beta Ziliani --- docs/syntax_and_semantics/c_bindings/lib.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/syntax_and_semantics/c_bindings/lib.md b/docs/syntax_and_semantics/c_bindings/lib.md index ef2837313..0d132c2e9 100644 --- a/docs/syntax_and_semantics/c_bindings/lib.md +++ b/docs/syntax_and_semantics/c_bindings/lib.md @@ -26,5 +26,6 @@ Lib functions are visible in the macro language anywhere in the program. lib LibFoo fun foo end + {{ LibFoo.methods }} # => [fun foo] ``` From a7ec17da6f8d4a6263bae28d3f37829cec65de91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Mon, 9 Jan 2023 17:54:03 +0100 Subject: [PATCH 4/4] Add reference to `TypeNode#methods` --- docs/syntax_and_semantics/c_bindings/lib.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/syntax_and_semantics/c_bindings/lib.md b/docs/syntax_and_semantics/c_bindings/lib.md index 0d132c2e9..d333f1473 100644 --- a/docs/syntax_and_semantics/c_bindings/lib.md +++ b/docs/syntax_and_semantics/c_bindings/lib.md @@ -20,7 +20,7 @@ Attributes can be omitted if the library is implicitly linked, as in the case of ## Reflection -Lib functions are visible in the macro language anywhere in the program. +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