Make evmenu 'goto' option argument accept a callable for deciding the next node.

This commit is contained in:
Griatch 2017-01-21 22:59:43 +01:00
parent 5b62a30ce6
commit 0aebbf6975

View file

@ -785,12 +785,24 @@ class EvMenu(object):
Run a node by name Run a node by name
Args: Args:
nodename (str): Name of node. nodename (str or callable): Name of node or a callable
to be called as `function(caller, raw_string)` or `function(caller)`
to return the actual goto string.
raw_string (str): The raw default string entered on the raw_string (str): The raw default string entered on the
previous node (only used if the node accepts it as an previous node (only used if the node accepts it as an
argument) argument)
""" """
if callable(nodename):
try:
if len(getargspec(nodename).args) > 1:
# callable accepting raw_string
nodename = nodename(self.caller, raw_string)
else:
nodename = nodename(self.caller)
except Exception:
self.caller.msg(_ERR_GENERAL.format(nodename=nodename), self._session)
raise
try: try:
# execute the node, make use of the returns. # execute the node, make use of the returns.
nodetext, options = self._execute_node(nodename, raw_string) nodetext, options = self._execute_node(nodename, raw_string)