diff options
author | dakkar <dakkar@thenautilus.net> | 2023-07-22 14:07:56 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2023-07-22 14:07:56 +0100 |
commit | 709cf92de411b7a57c7298f8d970901930c4ce0f (patch) | |
tree | 1c88dd977cc60698c8fc22d7eab0c80a2b294764 /bos-namespaces.sh | |
parent | `*-into` always takes the destination as `$1` (diff) | |
download | bash-object-system-709cf92de411b7a57c7298f8d970901930c4ce0f.tar.gz bash-object-system-709cf92de411b7a57c7298f8d970901930c4ce0f.tar.bz2 bash-object-system-709cf92de411b7a57c7298f8d970901930c4ce0f.zip |
fix block&namespace nesting
Diffstat (limited to 'bos-namespaces.sh')
-rw-r--r-- | bos-namespaces.sh | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/bos-namespaces.sh b/bos-namespaces.sh index 0cb794a..02f3df2 100644 --- a/bos-namespaces.sh +++ b/bos-namespaces.sh @@ -38,9 +38,25 @@ function bos-namespaces/store-dict-for-into() { result="$name" } +declare -a bos_namespace_stack + +function bos-namespaces/current-namespace-into() { + local -n bos_namespace_current_namespace_result="$1" + local IFS=/ + bos_namespace_current_namespace_result="${bos_namespace_stack[*]}" +} + +function bos-namespaces/push() { + bos_namespace_stack+=( "$1" ) +} + +function bos-namespaces/pop() { + unset "bos_namespace_stack[-1]" +} + # save all currently-visible functions in an associative array -function bos-namespaces/start() { - local namespace="$1";shift +function bos-namespaces/save-funcs() { + local namespace; bos-namespaces/current-namespace-into namespace local ns_store; bos-namespaces/store-dict-for-into ns_store saved_funcs "$namespace" local -n saved_funcs="$ns_store" local _ funcname @@ -56,12 +72,17 @@ function bos-namespaces/start() { # ones that differ function bos-namespaces/list-new-funcs-into() { local -n result="$1" - local namespace="$2" + local namespace; bos-namespaces/current-namespace-into namespace local ns_store; bos-namespaces/store-dict-for-into ns_store saved_funcs "$namespace" local -n saved_funcs="$ns_store" local _ funcname new_function while read -r _ _ funcname; do + # if a function already belong to this namespace, it's not new + if [[ "$funcname" == "$namespace"/* ]]; then + continue + fi + new_function="$(declare -pf "$funcname")" if [[ "$new_function" != "${saved_funcs["$funcname"]}" ]]; then result+=( "${funcname}" ) @@ -74,7 +95,7 @@ function bos-namespaces/list-new-funcs-into() { # rename a bunch of functions by prepending a prefix; restore the # saved function of the same name, if it exists function bos-namespaces/qualify-funcs() { - local namespace="$1";shift + local namespace; bos-namespaces/current-namespace-into namespace local ns_store; bos-namespaces/store-dict-for-into ns_store saved_funcs "$namespace" local -n saved_funcs="$ns_store" local _ funcname new_function |