[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: hush: tackling "local" in functions
From: Mike Frysinger <vapier () gentoo ! org>
Date: 2009-05-28 6:11:35
Message-ID: 200905280211.36499.vapier () gentoo ! org
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
about the only major thing i see missing in hush after testing on random
packages out there is the "local" keyword.
x=1
f() { local x=$((x + 3)) ; echo $x ; }
g() { local x=$((x + 1)) ; f ; echo $x ; }
g
echo $x
the keyword causes the variable to only apply to children of the active
function scope. so here, we should see:
5 - global 1 added to g()'s 1 added to f()'s 3
2 - global 1 added to g()'s 1 unaffected by f()
1 - global 1 unaffected by g() or f()
another example:
x=1
f() { x=2; }
g() { local x=3; f; echo $x; }
g
we see the x is declared local to g()'s scope, and f() modifies it since it is
called inside that scope.
based on these needs, i'm thinking:
- new variable state for set_local_var()
- when a variable is marked local and it shadows an existing variable, we
insert it into the linked list of variables before the existing copy
- at the end of run_and_free_list(), we walk the variable list destroying all
variables marked local
-mike
["signature.asc" (application/pgp-signature)]
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic