diff --git a/smnp/environment/environment.py b/smnp/environment/environment.py index 32a009f..aec354a 100644 --- a/smnp/environment/environment.py +++ b/smnp/environment/environment.py @@ -1,4 +1,4 @@ -from smnp.error.function import FunctionNotFoundException +from smnp.error.function import FunctionNotFoundException, MethodNotFoundException from smnp.error.runtime import RuntimeException @@ -10,6 +10,14 @@ class Environment(): self.customFunctions = {} self.callStack = [] #TODO remove + def invokeMethod(self, name, object, args): + for method in self.methods: # TODO to działa tylko dla wbudowanych funkcji + if method.name == name: + ret = method.call(self, [object, *args]) + if ret is not None: + return ret + raise MethodNotFoundException(object.type, name) # TODO method not found + def invokeFunction(self, name, args): for function in self.functions: # TODO to działa tylko dla wbudowanych funkcji if function.name == name: diff --git a/smnp/error/function.py b/smnp/error/function.py index c622f2b..3904a09 100644 --- a/smnp/error/function.py +++ b/smnp/error/function.py @@ -9,3 +9,8 @@ class IllegalFunctionInvocationException(SmnpException): class FunctionNotFoundException(SmnpException): def __init__(self, function): self.msg = f"Function '{function}' not found" + + +class MethodNotFoundException(SmnpException): + def __init__(self, object, method): + self.msg = f"Method '{method}' of type '{object}' not found" \ No newline at end of file