From fa32f7b824fa75dba6c61c47c4d78d4e933d7e80 Mon Sep 17 00:00:00 2001 From: Ugric Date: Sat, 25 Mar 2023 01:20:23 +0000 Subject: [PATCH] add anymap to allow map with __call__ in thread --- src/thread.go | 9 ++++++--- src/typeof.go | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/thread.go b/src/thread.go index 0b73e2b..1e8b8c0 100644 --- a/src/thread.go +++ b/src/thread.go @@ -11,9 +11,12 @@ func ArThread(args ...any) (any, ArErr) { } var tocall any switch x := args[0].(type) { - case Callable: - tocall = x - case builtinFunc: + case anymap: + if _, ok := x["__call__"]; !ok { + return nil, ArErr{TYPE: "TypeError", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true} + } + tocall = x["__call__"] + case builtinFunc, Callable: tocall = x default: return nil, ArErr{TYPE: "TypeError", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true} diff --git a/src/typeof.go b/src/typeof.go index fedeec6..3984d16 100644 --- a/src/typeof.go +++ b/src/typeof.go @@ -12,6 +12,8 @@ func typeof(val any) string { return "string" case []any: return "array" + case anymap: + return "map" case Callable: return "function" case builtinFunc: