summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2022-03-10 01:02:45 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2022-06-27 21:13:32 +0200
commit1ac8e11bba15551ad6473a57a585649757fefa6b (patch)
tree76e1f6524a7b290bc5b4eb53c2bbbcc6056b359c /doc
parenta2527ee53d9d8fe7a1c29b56f8450b9ef1f9c7bc (diff)
Filter: Implement mixed declarations of local variables
Allow variable declarations mixed with code, also in nested blocks with proper scoping, and with variable initializers. E.g: function fn(int a) { int b; int c = 10; if a > 20 then { b = 30; int d = c * 2; print a, b, c, d; } string s = "Hello"; }
Diffstat (limited to 'doc')
-rw-r--r--doc/bird.sgml23
1 files changed, 13 insertions, 10 deletions
diff --git a/doc/bird.sgml b/doc/bird.sgml
index 326fc7a8..f933128c 100644
--- a/doc/bird.sgml
+++ b/doc/bird.sgml
@@ -1260,8 +1260,8 @@ this:
<code>
filter not_too_far
-int var;
{
+ int var;
if defined( rip_metric ) then
var = rip_metric;
else {
@@ -1290,9 +1290,9 @@ local variables. Recursion is not allowed. Function definitions look like this:
<code>
function name ()
-int local_variable;
{
- local_variable = 5;
+ int local_variable;
+ int another_variable = 5;
}
function with_parameters (int parameter)
@@ -1301,16 +1301,19 @@ function with_parameters (int parameter)
}
</code>
-<p>Unlike in C, variables are declared after the <cf/function/ line, but before
-the first <cf/{/. You can't declare variables in nested blocks. Functions are
-called like in C: <cf>name(); with_parameters(5);</cf>. Function may return
-values using the <cf>return <m/[expr]/</cf> command. Returning a value exits
-from current function (this is similar to C).
+<p>Like in C programming language, variables are declared inside function body,
+either at the beginning, or mixed with other statements. Declarations may
+contain initialization. You can also declare variables in nested blocks, such
+variables have scope restricted to such block. There is a deprecated syntax to
+declare variables after the <cf/function/ line, but before the first <cf/{/.
+Functions are called like in C: <cf>name(); with_parameters(5);</cf>. Function
+may return values using the <cf>return <m/[expr]/</cf> command. Returning a
+value exits from current function (this is similar to C).
-<p>Filters are defined in a way similar to functions except they can't have
+<p>Filters are defined in a way similar to functions except they cannot have
explicit parameters. They get a route table entry as an implicit parameter, it
is also passed automatically to any functions called. The filter must terminate
-with either <cf/accept/ or <cf/reject/ statement. If there's a runtime error in
+with either <cf/accept/ or <cf/reject/ statement. If there is a runtime error in
filter, the route is rejected.
<p>A nice trick to debug filters is to use <cf>show route filter <m/name/</cf>