Compare commits

...

4 Commits

Author SHA1 Message Date
Gouvernathor db1a4367ae Use the docstring instead of a rst entry
no need to edit the doc generation script actually
2023-07-19 15:00:38 +02:00
Gouvernathor fe8dc69cde Tweak doc entry 2023-07-16 18:38:55 +02:00
Gouvernathor 3ebd020841 Document addition
Unless I add deco or decorator as a :doc: option, decorators can't be documented by docstring
2023-07-16 18:24:10 +02:00
Gouvernathor 1bc5e25ed3 Add register_decorator 2023-07-16 18:13:48 +02:00
2 changed files with 60 additions and 1 deletions
+1 -1
View File
@@ -102,7 +102,7 @@ from renpy.character import show_display_say, predict_show_display_say, display_
import renpy.audio.sound as sound
import renpy.audio.music as music
from renpy.statements import register as register_statement
from renpy.statements import register as register_statement, register_decorator
from renpy.text.extras import check_text_tags
from renpy.memory import profile_memory, diff_memory, profile_rollback
+59
View File
@@ -309,6 +309,65 @@ def register(
parsers.add(name, parse_data)
# import inspect # only works in py3
# register_params = frozenset(inspect.signature(register).parameters) - {"name", "parse", "execute"}
register_params = frozenset((
# "name", # special-cased
# "parse", # special-cased
"lint",
# "execute", # special-cased
"predict",
"next",
"scry",
"block",
"init",
"translatable",
"execute_init",
"init_priority",
"label",
"warp",
"translation_strings",
"force_begin_rollback",
"post_execute",
"post_label",
"predict_all",
"predict_next",
"execute_default",
"reachable",
))
def register_decorator(cls):
"""
:doc: statement_register decorator
:args:
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` parameter to :func:`renpy.register_statement` should
either be the class constructor itself, or a method named ``parse``
(likely a class method or static method) returning an instance of
the class.
For the `execute` parameter, Ren'Py will look for a method named
``execute`` on the class, or if it is not found, will use the class's
``__call__`` method to call like a function the object created by `parse`.
All other parameters to :func:`renpy.register_statement` should be set as
class attributes or methods with the same name.
"""
name = getattr(cls, "name", cls.__name__)
parse = getattr(cls, "parse", cls)
execute = getattr(cls, "execute", None) or cls.__call__
register(
name,
parse=parse,
execute=execute,
**{k:getattr(cls, k) for k in register_params.intersection(vars(cls))}
)
return cls
def parse(node, line, subblock):
"""