MCPcopy Create free account
hub / github.com/battlecode/battlecode-2018 / Method

Class Method

bindings/frankenswig/function.py:69–106  ·  view source on GitHub ↗

A function contained within some type.

Source from the content-addressed store, hash-verified

67 return Function.pyentry(self.type, self.args, self.name, self.docs) + s(body, indent=4)
68
69class Method(Function):
70 '''A function contained within some type.'''
71 def __init__(self, type, container, method_name, args, body='', docs='', pyname=None, static=False, getter=False):
72 self.container = container
73 self.method_name = method_name
74 self.static = static
75 super().__init__(type, f'{self.container}_{self.method_name}', args, body, docs)
76 if pyname is None:
77 self.pyname = self.method_name
78 else:
79 self.pyname = pyname
80 self.getter = getter
81
82 def to_swig(self):
83 result = s(f'''\
84 %newobject {self.method_name};
85 {self.type.to_swig()} {self.method_name}({', '.join(a.to_swig() for a in self.args[1:])});
86 ''')
87 return result
88
89 def to_python(self):
90 if self.static:
91 args = self.args
92 else:
93 args = [Var(self.args[0].type, 'self')] + self.args[1:]
94 pyargs = ', '.join(a.type.wrap_python_value(a.name) for a in args)
95
96 body = f'result = _lib.{self.name}({pyargs})\n'
97 body += '_check_errors()\n'
98 body += self.type.python_postfix()
99 body += 'return result\n'
100 if self.static:
101 pre = '@staticmethod\n'
102 elif self.getter:
103 pre = '@property\n'
104 else:
105 pre = ''
106 return pre + Function.pyentry(self.type, args, self.pyname, self.docs) + s(body, indent=4)
107
108class FunctionWrapper(Function):
109 def __init__(self, program, type, name, args):

Callers 5

methodMethod · 0.85
serializeMethod · 0.85
debugMethod · 0.85
memberMethod · 0.85
methodMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected