Improve environment #2

This commit is contained in:
Bartłomiej Pluta
2019-07-04 12:02:46 +02:00
parent b60dedc769
commit f86055272e
2 changed files with 14 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
from smnp.error.function import FunctionNotFoundException from smnp.error.function import FunctionNotFoundException, MethodNotFoundException
from smnp.error.runtime import RuntimeException from smnp.error.runtime import RuntimeException
@@ -10,6 +10,14 @@ class Environment():
self.customFunctions = {} self.customFunctions = {}
self.callStack = [] #TODO remove 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): def invokeFunction(self, name, args):
for function in self.functions: # TODO to działa tylko dla wbudowanych funkcji for function in self.functions: # TODO to działa tylko dla wbudowanych funkcji
if function.name == name: if function.name == name:

View File

@@ -9,3 +9,8 @@ class IllegalFunctionInvocationException(SmnpException):
class FunctionNotFoundException(SmnpException): class FunctionNotFoundException(SmnpException):
def __init__(self, function): def __init__(self, function):
self.msg = f"Function '{function}' not found" 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"