From 601e20516222215b7a8f1989878fb8b8073ec23d Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Thu, 22 Dec 2022 15:50:18 +0900 Subject: [PATCH] toolbox.sh: Make interface methods point to error stub by default 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 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/toolbox.sh b/toolbox.sh index e9cbfd2..802c5cc 100644 --- a/toolbox.sh +++ b/toolbox.sh @@ -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 -- 2.47.3