]> git.corax.cc Git - toolbox/commitdiff
toolbox.sh: Make interface methods point to error stub by default
authorMatthias Kruk <m@m10k.eu>
Thu, 22 Dec 2022 06:50:18 +0000 (15:50 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 9 Jan 2023 04:20:17 +0000 (13:20 +0900)
Modules that declare an interface are expected to implement all
methods, prefixing method names with an underscore. However, since
there may be (partially) unimplemented interfaces, the framework
should not make such assumptions about implementations.

This commit modifies the implementation of interfaces so that
methods reference an error stub by default, which warns the caller
that the method is not implemented.

toolbox.sh

index e9cbfd20dcf83d7fe775e1c7d7a1fa563148151b..802c5cc823f25c7ebe5e8a2934d0d737a2b82aeb 100644 (file)
@@ -52,6 +52,7 @@ __toolbox_init() {
        readonly -f interface
        readonly -f implements
        readonly -f calling_module
+       readonly -f method_not_implemented
 
        return 0
 }
@@ -171,6 +172,16 @@ calling_module() {
        return 0
 }
 
+method_not_implemented() {
+       local method
+
+       method="${FUNCNAME[1]}"
+       method="${method#_}"
+
+       echo "ERROR: $method: Not implemented" 1>&2
+       return 127
+}
+
 interface() {
        local methods=("$@")
 
@@ -210,7 +221,7 @@ interface() {
 
        # Set the entries in the vtable
        for method in "${methods[@]}"; do
-               interface["$method"]="_${name}_$method"
+               interface["$method"]=method_not_implemented
        done
 
        return 0