From f156b3c1ad1e7ec248364803331d2eb57e607295 Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli Date: Thu, 20 Jul 2023 14:51:27 +0100 Subject: test next/method --- bos-dispatch.sh | 24 ++++++++++++++++++++++-- bos-mop.sh | 2 +- test.sh | 15 ++++++++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/bos-dispatch.sh b/bos-dispatch.sh index afefb5e..8489765 100644 --- a/bos-dispatch.sh +++ b/bos-dispatch.sh @@ -1,15 +1,35 @@ #!bash +# return the closest non-BOS function name from the call stack +function bos-dispatch/caller-into() { + local -n bos_dispatch_caller_result="$1" + + local idx + for caller in "${FUNCNAME[@]}"; do + if [[ ! $caller =~ ^bos[_/-] ]]; then + bos_dispatch_caller_result="$caller" + return 0 + fi + done + + return 1 +} + # the bare-bones / fallback dispatcher function bos-dispatch/invoke() { local class="$1";shift local self_id="$1";shift local method="$1";shift + local qualified_method="$class/$method" + + if [[ "$method" =~ / ]]; then + qualified_method="$method" + fi - if declare -F "$class/$method" >/dev/null; then + if declare -F "$qualified_method" >/dev/null; then local self bos-object-id/pack-self-into "$class" "$self_id" self - "$class/$method" "$@" + "$qualified_method" "$@" return $? fi diff --git a/bos-mop.sh b/bos-mop.sh index a1b5f20..1e69c47 100644 --- a/bos-mop.sh +++ b/bos-mop.sh @@ -51,7 +51,7 @@ function bos/mop/base/find-method-into() { done # TODO: better error / failure - >&2 echo "method $method not found" + >&2 echo "method $method not found via class $class" return 1 } diff --git a/test.sh b/test.sh index f161647..1a4371e 100644 --- a/test.sh +++ b/test.sh @@ -26,10 +26,23 @@ class B; do done +class C; do + extends B + + function thing() { + echo "<$self> C/thing ($*)" + + $self next/method "$@" + } + +done + A new-into objA B new-into objB +C new-into objC $objA thing 1 2 3 $objB thing 4 5 6 -$objB other 7 8 9 +$objC thing 7 8 9 +$objB other a b c -- cgit v1.2.3