diff options
Diffstat (limited to 'swig')
-rwxr-xr-x | swig/lv2_list.py | 6 | ||||
-rw-r--r-- | swig/slv2.i | 23 |
2 files changed, 21 insertions, 8 deletions
diff --git a/swig/lv2_list.py b/swig/lv2_list.py index 0f6e248..4dc4f97 100755 --- a/swig/lv2_list.py +++ b/swig/lv2_list.py @@ -4,7 +4,5 @@ import slv2; w = slv2.World() w.load_all() -plugins = w.get_all_plugins() - -for i in range(0, plugins.size()): - print plugins[i].uri() +for p in w.get_all_plugins(): + print p.uri() diff --git a/swig/slv2.i b/swig/slv2.i index b044310..5020767 100644 --- a/swig/slv2.i +++ b/swig/slv2.i @@ -37,7 +37,7 @@ typedef struct { SLV2Plugin me; } Plugin; } ~Plugin() { - /* FIXME: free SLV2Plugin? */ + /* FIXME: free SLV2Plugin here? */ free($self); } @@ -45,7 +45,7 @@ typedef struct { SLV2Plugin me; } Plugin; const char* uri() { return slv2_plugin_get_uri($self->me); } }; -typedef struct { SLV2Plugins me; } Plugins; +typedef struct { SLV2World world; SLV2Plugins me; } Plugins; %extend Plugins { Plugins(SLV2World w, SLV2Plugins p) { Plugins* ret = malloc(sizeof(Plugins)); @@ -68,6 +68,23 @@ typedef struct { SLV2Plugins me; } Plugins; else return NULL; } + +%pythoncode %{ + def __iter__(self): + class Iterator(object): + def __init__(self, plugins): + self.plugins = plugins + self.iter = 0 + + def next(self): + if self.iter < self.plugins.size(): + self.iter += 1 + return Plugin(slv2_plugins_get_at(self.plugins.me, self.iter-1)) + else: + raise StopIteration + + return Iterator(self) +%} }; typedef struct { SLV2World me; } World; @@ -82,8 +99,6 @@ typedef struct { SLV2World me; } World; slv2_world_free($self->me); free($self); } - /*World() { $self->me = slv2_world_new(); } - ~World() { slv2_world_free($self->me); }*/ void load_all() { slv2_world_load_all($self->me); } void load_bundle(const char* path) { slv2_world_load_bundle($self->me, path); } |