Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25243 > unrolled thread
| Started by | Temia Eszteri <lamialily@cleverpun.com> |
|---|---|
| First post | 2012-07-12 21:03 -0700 |
| Last post | 2012-07-13 11:49 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
Writing a wrapper - any tips? Temia Eszteri <lamialily@cleverpun.com> - 2012-07-12 21:03 -0700
Re: Writing a wrapper - any tips? "Martin P. Hellwig" <martin.hellwig@gmail.com> - 2012-07-13 00:39 -0700
Re: Writing a wrapper - any tips? Stefan Behnel <stefan_ml@behnel.de> - 2012-07-13 11:49 +0200
| From | Temia Eszteri <lamialily@cleverpun.com> |
|---|---|
| Date | 2012-07-12 21:03 -0700 |
| Subject | Writing a wrapper - any tips? |
| Message-ID | <d37vv7ds3s1sus5jr9cvn17gje775l3l4l@4ax.com> |
I'm going to be looking into writing a wrapper for the Allegro 5 game development libraries, either with ctypes or Cython. They technically have a basic 1:1 ctypes wrapper currently, but I wanted to make something more pythonic, because it'd be next to impossible to deal with the memory management cleanly in the script itself. Anything I should keep in mind? Any tips to pass on to a first-time module writer, pitfalls to watch out for, etc.? ~Temia P.S. I know another game development library, SDL, was wrapped for Python in the form of Pygame, but I *really* don't like SDL. -- The amazing programming device: fuelled entirely by coffee, it codes while awake and tests while asleep!
[toc] | [next] | [standalone]
| From | "Martin P. Hellwig" <martin.hellwig@gmail.com> |
|---|---|
| Date | 2012-07-13 00:39 -0700 |
| Message-ID | <9a3fe09a-82dd-4623-a6da-15a23633db3b@googlegroups.com> |
| In reply to | #25243 |
On Friday, 13 July 2012 05:03:23 UTC+1, Temia Eszteri wrote: > I'm going to be looking into writing a wrapper for the Allegro 5 game > development libraries, either with ctypes or Cython. They technically > have a basic 1:1 ctypes wrapper currently, but I wanted to make > something more pythonic, because it'd be next to impossible to deal > with the memory management cleanly in the script itself. > > Anything I should keep in mind? Any tips to pass on to a first-time > module writer, pitfalls to watch out for, etc.? <cut> I would split the wrapping in layers, the lowest layer is a one on one exposure of the library with your wrapper, I would rather avoid ctypes for performance reasons, however if performance is not a concern ctypes is excellent and broadly available. The next layer is purely there to make the lower layer pythonic, i.e. apply namespaces, automatic handling of memory, PEP8 naming convetions, etc. etc. just what you would expect from a modern pure python module The next layer, if you want to, contains tools that are often used in that concept, think in the line of design patterns. hth -- mph
[toc] | [prev] | [next] | [standalone]
| From | Stefan Behnel <stefan_ml@behnel.de> |
|---|---|
| Date | 2012-07-13 11:49 +0200 |
| Message-ID | <mailman.2072.1342172977.4697.python-list@python.org> |
| In reply to | #25253 |
Martin P. Hellwig, 13.07.2012 09:39: > On Friday, 13 July 2012 05:03:23 UTC+1, Temia Eszteri wrote: >> I'm going to be looking into writing a wrapper for the Allegro 5 game >> development libraries, either with ctypes or Cython. They technically >> have a basic 1:1 ctypes wrapper currently, but I wanted to make >> something more pythonic, because it'd be next to impossible to deal >> with the memory management cleanly in the script itself. >> >> Anything I should keep in mind? Any tips to pass on to a first-time >> module writer, pitfalls to watch out for, etc.? > <cut> > I would split the wrapping in layers, the lowest layer is a one on one > exposure of the library with your wrapper, I would rather avoid ctypes > for performance reasons, however if performance is not a concern ctypes > is excellent and broadly available. > > The next layer is purely there to make the lower layer pythonic, i.e. > apply namespaces, automatic handling of memory, PEP8 naming convetions, > etc. etc. just what you would expect from a modern pure python module > > The next layer, if you want to, contains tools that are often used in > that concept, think in the line of design patterns. And the good thing about Cython in this context is that even if performance *is* a concern, you can move code around between all three layers freely in order to adjust it to your performance requirements and even drop the lowest layer entirely. In fact, my advice is to really skip that lowest layer in a Cython wrapper, because if it's really just a 1:1 mapping, it's going to end up with a lot of boring and redundant code and you won't gain anything from it. Stefan
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web