From 5643d1c4ff222632947462458ea7e04df151c4f3 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Mon, 9 Jan 2023 14:18:39 +0900 Subject: [PATCH] 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. --- toolbox.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) 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 } -- 2.47.3