From 6297ec2ae4263c346a9f7cf036055ca8cdb72c78 Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli Date: Fri, 14 Jul 2023 15:22:38 +0100 Subject: inheritance via MOP *probably*, I'm still not completely certain I've found all the weirdness --- bos-mop.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'bos-mop.sh') diff --git a/bos-mop.sh b/bos-mop.sh index 3b06216..b3b03f0 100644 --- a/bos-mop.sh +++ b/bos-mop.sh @@ -23,6 +23,12 @@ function bos/mop/base/find-method-into() { local mro_store; $self mro-for-into "$class" mro_store local -n mro="$mro_store" + + # minimal MRO: the class itself + if [[ "${#mro[@]}" -eq 0 ]]; then + mro=( "$class" ) + fi + local idx=0 # if we don't have a $start_from_class, it means we're doing the @@ -67,14 +73,18 @@ function bos/mop/base/invoke() { fi # get the first class that defines the method - local to_invoke - $self find-method-into "$class" "$start_from_class" "$method" to_invoke + + # there is some fuckery going on with namerefs, recursion, and + # local; this is a probably-bad-but-works workaround: use a + # different variable name in different recursive calls + local ffsname="to_invoke_${#FUNCNAME[*]}" + $self find-method-into "$class" "$start_from_class" "$method" "$ffsname" # TODO: make the fields accessible! - local self bos-object-id/pack-self-into "$class" "$object_id" self # call it - "$to_invoke" "$@" + eval "\"\$$ffsname\" \"\$@\"" + return $? } -- cgit v1.2.3