]> git.corax.cc Git - toolbox/commitdiff
toolbox.sh: Don't require all interface methods to be implemented
authorMatthias Kruk <m@m10k.eu>
Mon, 9 Jan 2023 05:18:39 +0000 (14:18 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 9 Jan 2023 05:18:39 +0000 (14:18 +0900)
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

index c3dd29a378d4773214f47c63110e970fe5120aa3..f8549e248538ece03df57aa24cb423346405c974 100644 (file)
@@ -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
 }