Add decorator
This commit is contained in:
parent
17ebf50170
commit
8e80555393
@ -1,3 +1,27 @@
|
||||
python early hide:
|
||||
import inspect
|
||||
__register_params = frozenset(inspect.signature(renpy.register_statement).parameters).difference({"name", "parse"})
|
||||
def register_decorator(cls):
|
||||
"""
|
||||
A class decorator which registers a new statement.
|
||||
|
||||
The name of the statement will be the class name unless a `name` class attribute is present, which should be a string.
|
||||
|
||||
The `parse` method should be a static method that returns an object which will be passed to the other methods as `self`.
|
||||
Returning an instance of the class is disabled for now.
|
||||
"""
|
||||
# security
|
||||
def raiser(*args, **kwargs):
|
||||
raise NotImplementedError("Returning an instance of the class is disabled")
|
||||
cls.__init__ = raiser
|
||||
|
||||
name = getattr(cls, "name", cls.__name__)
|
||||
parse = getattr(cls, "parse", cls) # left in
|
||||
renpy.register_statement(name,
|
||||
parse=parse,
|
||||
**{k:getattr(cls, k) for k in __register_params.intersection(vars(cls))})
|
||||
return cls
|
||||
|
||||
python early:
|
||||
def parse_chibi(l):
|
||||
who = l.simple_expression()
|
||||
|
Loading…
Reference in New Issue
Block a user