Wizzup?
2011-01-24 15:49:42
Was making something similar for a different project and then suddenly realized we could use this with pymml. What it basically does is add a set of functions to an existing class, dynamically. Then that class would call the CDLL/WinDLL and all the actual function. I could probably add type / variable checking to this as well…
Not sure if it is better than the current system; just throwing it out here.
Not sure if it is better than the current system; just throwing it out here.
import types
_methods = { 'find_color' : ('find_color', """Finds color""") }
class B(object):
def __getattr__(self, name):
print 'Calling...'
# Call CTypes CDLL/WinDLL here
if name in ('find_color',):
return lambda *x: 42
else:
raise AttributeError, name
class A(object):
def __init__(self, b):
self.b = b
for x, y in _methods.iteritems():
caller = (lambda name: lambda self, *args: getattr(self.b,name)(*args))(y[0])
caller.__doc__ = y[1]
setattr(A, x, types.MethodType(caller, None, A))
a = A(B())
a.find_color(x, y)