summaryrefslogtreecommitdiff
path: root/bos-dispatch.sh
diff options
context:
space:
mode:
authorGianni Ceccarelli <gianni.ceccarelli@broadbean.com>2023-07-20 14:51:27 +0100
committerGianni Ceccarelli <gianni.ceccarelli@broadbean.com>2023-07-20 14:52:02 +0100
commitf156b3c1ad1e7ec248364803331d2eb57e607295 (patch)
tree58c66d3db1e2adc5896b484adcf99d8630e59112 /bos-dispatch.sh
parentconstructors & class methods! (diff)
downloadbash-object-system-f156b3c1ad1e7ec248364803331d2eb57e607295.tar.gz
bash-object-system-f156b3c1ad1e7ec248364803331d2eb57e607295.tar.bz2
bash-object-system-f156b3c1ad1e7ec248364803331d2eb57e607295.zip
test next/method
Diffstat (limited to 'bos-dispatch.sh')
-rw-r--r--bos-dispatch.sh24
1 files changed, 22 insertions, 2 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