diff options
author | Gianni Ceccarelli <gianni.ceccarelli@broadbean.com> | 2023-07-14 16:36:10 +0100 |
---|---|---|
committer | Gianni Ceccarelli <gianni.ceccarelli@broadbean.com> | 2023-07-14 16:36:10 +0100 |
commit | 86c37a00dd9ec82c261e3c9f7997051aabaa228b (patch) | |
tree | b682b6e94d62e293aefa353008b33f85b57c6ed3 /bos-sugar.sh | |
parent | some sugaring (diff) | |
download | bash-object-system-86c37a00dd9ec82c261e3c9f7997051aabaa228b.tar.gz bash-object-system-86c37a00dd9ec82c261e3c9f7997051aabaa228b.tar.bz2 bash-object-system-86c37a00dd9ec82c261e3c9f7997051aabaa228b.zip |
constructors & class methods!
"class methods" are not actually a thing, we declare a function for
each class, that invokes on the class name and object-id=0 (object-id
start from 1 for real objects)
Diffstat (limited to 'bos-sugar.sh')
-rw-r--r-- | bos-sugar.sh | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/bos-sugar.sh b/bos-sugar.sh index e211b5e..a199ed9 100644 --- a/bos-sugar.sh +++ b/bos-sugar.sh @@ -18,9 +18,9 @@ function bos-sugar/block() { declare -a bos_sugar_class_stack function bos-sugar/current-class-into() { - local -n result="$1" + local -n bos_sugar_current_class_result="$1" local IFS=/ - result="${bos_sugar_class_stack[*]}" + bos_sugar_current_class_result="${bos_sugar_class_stack[*]}" } function bos-sugar/set-metaclass-for-current-class() { @@ -47,12 +47,25 @@ function bos-sugar/class-open() { $metaclass_object set-superclasses-for "$fq_class" "$@" } + eval "function $fq_class { bos-dispatch/invoke \"$fq_class\" 0 \"\$@\"; }" + bos-namespaces/start "$fq_class" - return 0 -} + # this will get renamed into the class + function new-into() { + local class _; bos-object/unpack-self-into "$self" class _ + local -n new_into_result="$1"; shift + local metaclass_ref; bos-namespaces/store-scalar-for-into meta "$class" metaclass_ref + local -n metaclass_object="$metaclass_ref" + local new_object + $metaclass_object create-object-into new_object "$class" + new_into_result="$new_object" + } + + return 0 +} function bos-sugar/class-close() { local class="$1" |