From e7b46c89b4a9c4487cac5386e7e86a4a4e951d07 Mon Sep 17 00:00:00 2001 From: Griatch Date: Thu, 27 Oct 2011 10:18:18 +0200 Subject: [PATCH] Added the ability for the Command.func() method to return a value. This allows to potentially do e.g. value = caller.execute_cmd('cmdname'). Not used at all by default commands nor the engine itself, but potentially useful for admins wanting to implement some sort of 'nested' command structure, maybe using a custom input language. --- src/commands/cmdhandler.py | 6 ++++-- src/objects/models.py | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/commands/cmdhandler.py b/src/commands/cmdhandler.py index 365ee3b52b..2186ef2d69 100644 --- a/src/commands/cmdhandler.py +++ b/src/commands/cmdhandler.py @@ -234,11 +234,13 @@ def cmdhandler(caller, raw_string, unloggedin=False, testing=False): # Parse and execute cmd.parse() - cmd.func() + # (return value is normally None) + ret = cmd.func() # post-command hook cmd.at_post_cmd() - # Done! + # Done! By default, Evennia does not use this return at all + return ret except ExecSystemCommand, exc: # Not a normal command: run a system command, if available, diff --git a/src/objects/models.py b/src/objects/models.py index 9cfea701a4..5b8e0be4f5 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -556,6 +556,11 @@ class ObjectDB(TypedObject): Do something as this object. This command transparently lets its typeclass execute the command. raw_string - raw command input coming from the command line. + + The return from this method is None for all default commands + (it's the return value of cmd.func()) and is not used in any + way by the engine. It might be useful for admins wanting to + implement some sort of 'nested' command structure though, """ # nick replacement - we require full-word matching. @@ -568,7 +573,7 @@ class ObjectDB(TypedObject): if nick.db_nick in raw_list: raw_string = raw_string.replace(nick.db_nick, nick.db_real, 1) break - cmdhandler.cmdhandler(self.typeclass, raw_string) + return cmdhandler.cmdhandler(self.typeclass, raw_string) def msg(self, message, from_obj=None, data=None): """