A function declaration inside a lib, or a top-level C function definition.
Every function node is equivalent to:
fun {{ node.name }} {% if real_name = node.real_name %}= {{ real_name }}{% end %}(
{% for arg in node.args %} {{ arg }}, {% end %}
{% if node.variadic? %} ... {% end %}
) {% if return_type = node.return_type %}: {{ return_type }}{% end %}
{% if node.has_body? %}
{{ body }}
end
{% end %} Returns the parameters of the function.
Returns the body of the function, if any.
Returns whether this function has a body.
Returns the name of the function in Crystal.
Returns the real C name of the function, if any.
Returns the return type of the function, if specified.
Returns whether the function is variadic.
Crystal::Macros::ASTNode
Returns the parameters of the function.
This does not include the variadic parameter.
Returns the body of the function, if any.
Both top-level funs and lib funs may return a Nop. Instead, #has_body? can be used to distinguish between the two.
macro body_class(x)
{{ (x.is_a?(LibDef) ? x.body : x).body.class_name }}
end
body_class(lib MyLib
fun foo
end) # => "Nop"
body_class(fun foo
end) # => "Nop" Returns whether this function has a body.
Top-level funs have a body, whereas lib funs do not.
macro has_body(x)
{{ (x.is_a?(LibDef) ? x.body : x).has_body? }}
end
has_body(lib MyLib
fun foo
end) # => false
has_body(fun foo
end) # => true Returns the real C name of the function, if any.
Returns whether the function is variadic.
© 2012–2026 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.19.0/Crystal/Macros/FunDef.html