From: Matthias Kruk Date: Mon, 9 Jan 2023 05:18:39 +0000 (+0900) Subject: toolbox.sh: Don't require all interface methods to be implemented X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=5643d1c4ff222632947462458ea7e04df151c4f3;p=toolbox toolbox.sh: Don't require all interface methods to be implemented The interface/implements mechanism requires a module to implement all methods of the interface that it implements, making modules that extend other modules impossible. This commit modifies the `implements()' function to remove the restriction that a module must implement all interface methods. --- diff --git a/toolbox.sh b/toolbox.sh index c3dd29a..f8549e2 100644 --- a/toolbox.sh +++ b/toolbox.sh @@ -290,18 +290,12 @@ implements() { interface="${__TOOLBOX_INTERFACES[$iface]}" module=$(calling_module) - # Check if all methods are implemented before modifying the vtable for method in "${!interface[@]}"; do - if ! declare -f "${module}_$method" &>/dev/null; then - echo "ERROR: Module $module does not implement the method \"$method\"" 1>&2 - return 1 + if have_method "${module}_$method"; then + interface["$method"]="${module}_$method" fi done - for method in "${!interface[@]}"; do - interface["$method"]="${module}_$method" - done - return 0 }