[Pyobjc-dev] Bridging enumerated types
Brought to you by:
ronaldoussoren
From: Leigh S. <le...@to...> - 2001-04-15 18:34:42
|
The Python-ObjC works really well for interfacing the MusicKit (non-GUI) to Python, thanks to the developers! One issue we face is that the MusicKit uses a very large collection (200 odd) of enumerated types for musical note parameters (pitch, duration, synthesis parameters etc). It would be really nice to define these within Python, but to avoid synchronizing between two code bases, it would be nicer to have them automatically derived from the C source. Two approaches come to mind, either I create a C function that includes the params.h file (containing the enums) and then exports them via the usual Python C bridge or I write a python script to read a header file, extract all the enums (including integer assignments) and create the variables then. The issues I can see are the former could require a lot of repetitive code (possibly automatically created using sed/Python/perl) and would require that binary to be complied and placed into the standard Python library area. Each program would then need a "import MusicKit" statement, which could (I assume) do the NSBundle.load('MusicKit.framework') statement. The latter parsing approach would need to create all the variables at run time (obviously possible, but I currently lack that knowledge of Python) and would follow the NSBundle.load('MusicKit.framework') statement with something like enumParse('MusicKit.framework/Headers/params.h'). Perhaps there is already some similar solution since this is not ObjC specific, any bridge to a large C code base using many enums would have the same issue. Of course I'd look to contribute the solution to either pyobjc or the standard Python archive, depending on where it is best located. Any suggestions? |