Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Writing a wrapper - any tips?

Reply
Thread Tools

Writing a wrapper - any tips?

 
 
Temia Eszteri
Guest
Posts: n/a
 
      07-13-2012
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!
 
Reply With Quote
 
 
 
 
Martin P. Hellwig
Guest
Posts: n/a
 
      07-13-2012
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
 
Reply With Quote
 
 
 
 
Stefan Behnel
Guest
Posts: n/a
 
      07-13-2012
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing an OO wrapper (UI) Nit Khair Ruby 9 10-12-2008 06:34 PM
any python wrapper to call .lib static library(ufmod.lib)? est Python 1 02-16-2008 10:56 AM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM
[Dream] A meta-wrapper module to interface any C dynamic library Francesco Bochicchio Python 6 07-04-2003 05:39 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57