Mercurial > touhou
comparison pytouhou/vm/common.py @ 69:a142e57218a0
Refactor. Move VMs to pytouhou.vm.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sat, 27 Aug 2011 10:58:54 +0200 |
parents | |
children | 69ec72b990a4 |
comparison
equal
deleted
inserted
replaced
68:a2459defd4b6 | 69:a142e57218a0 |
---|---|
1 # -*- encoding: utf-8 -*- | |
2 ## | |
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> | |
4 ## | |
5 ## This program is free software; you can redistribute it and/or modify | |
6 ## it under the terms of the GNU General Public License as published | |
7 ## by the Free Software Foundation; version 3 only. | |
8 ## | |
9 ## This program is distributed in the hope that it will be useful, | |
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ## GNU General Public License for more details. | |
13 ## | |
14 | |
15 | |
16 class MetaRegistry(type): | |
17 def __new__(mcs, name, bases, classdict): | |
18 instruction_handlers = {} | |
19 for item in classdict.itervalues(): | |
20 try: | |
21 instruction_ids = item._instruction_ids | |
22 except AttributeError: | |
23 pass | |
24 else: | |
25 for id_ in instruction_ids: | |
26 instruction_handlers[id_] = item | |
27 classdict['_handlers'] = instruction_handlers | |
28 return type.__new__(mcs, name, bases, classdict) | |
29 | |
30 | |
31 | |
32 def instruction(instruction_id): | |
33 def _decorator(func): | |
34 if not hasattr(func, '_instruction_ids'): | |
35 func._instruction_ids = set() | |
36 func._instruction_ids.add(instruction_id) | |
37 return func | |
38 return _decorator |