This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Less verbose Python commands


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 1/10/10 3:00 AM, Daniel Colascione wrote:
> [snip]

Err, this version propagates docstrings to command help too:

def command(*init_args):
    def decorator(func):
        def init_func(self):
            gdb.Command.__init__(self, *init_args)

        def invoke_func(self, argument, from_tty):
            func(argument, from_tty)

        type('Command_' + init_args[0].replace(' ', '_'),
             (gdb.Command,),
             { '__init__': init_func,
               '__doc__': func.__doc__,
               'invoke': invoke_func })()
        return func
    return decorator

@command('tracked', COMMAND_DATA, COMPLETE_NONE, True)
def func(argument, from_tty):
    "Commands having to do with tracked things"

@command('tracked types', COMMAND_DATA)
def func(argument, from_tty):
    "List the types of objects which are tracked"
    print parse_and_eval('2+2')

# etc.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)

iEYEARECAAYFAktJjEAACgkQ17c2LVA10VutRwCgucOLY5Vn8aNS2+XZZUpSZUaA
AfUAn0m+MbHAcrC1LuL3jrdPH17QO1st
=Y4db
-----END PGP SIGNATURE-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]