From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5489 invoked by alias); 10 Jan 2010 08:05:16 -0000 Received: (qmail 5471 invoked by uid 22791); 10 Jan 2010 08:05:15 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from lo.gmane.org (HELO lo.gmane.org) (80.91.229.12) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 10 Jan 2010 08:05:10 +0000 Received: from list by lo.gmane.org with local (Exim 4.50) id 1NTsnK-0004oc-8u for gdb-patches@sources.redhat.com; Sun, 10 Jan 2010 09:05:06 +0100 Received: from cpe-67-247-228-249.buffalo.res.rr.com ([67.247.228.249]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 10 Jan 2010 09:05:06 +0100 Received: from daniel by cpe-67-247-228-249.buffalo.res.rr.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 10 Jan 2010 09:05:06 +0100 To: gdb-patches@sources.redhat.com From: Daniel Colascione Subject: Less verbose Python commands Date: Sun, 10 Jan 2010 08:05:00 -0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-01/txt/msg00221.txt.bz2 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 import os, sys, gdb # Using this 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, 'invoke': invoke_func })() return func return decorator # We can more easily write commands that look like this: def register(): @command('fiber', gdb.COMMAND_DATA, gdb.COMPLETE_NONE, True) def func(argument, from_tty): print "Hi, I'm a fiber prefix!" @command('fiber list', gdb.COMMAND_DATA) def func(argument, from_tty): print "List fibers here" # Less verbose, isn't it? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (Darwin) iEYEARECAAYFAktJiTQACgkQ17c2LVA10VsB+wCg27MtSJmw7sQAuJsTW5u/gPQ8 pAQAn0F/2oOW/r5M1iDY8AQOl6ZaWPVh =cbAs -----END PGP SIGNATURE-----