Created
October 1, 2014 01:41
-
-
Save RemyPorter/562b2979b12c16471d93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EffectCompose(EffectMeta): | |
def __init__(cls, name, bases, dct): | |
super().__init__(name, bases, dct) | |
def compose(a,b,abort_on_fail=False): | |
if not a: | |
return b | |
if abort_on_fail: | |
def f(statecont, *args, **kwargs): | |
res = a(statecont) | |
if res.opstate: | |
return b(res) | |
else: | |
def f(statecont, *args, **kwargs): | |
return b(a(statecont)) | |
return f | |
behaviors = dct["behaviors"] | |
d = "" | |
f = None | |
for b in behaviors: | |
f = compose(f, b) | |
d += "\n{0}".format(b.__doc__) | |
def call(self, state, *args, **kwargs): | |
return f(state, *args, **kwargs) | |
def init(self): | |
pass | |
cls.__init__ = init | |
cls.__call__ = call | |
cls.__doc__ = d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment