2009/9/8 Stefan Seefeld <[email protected]>
> On 09/08/2009 10:51 AM, Gustavo Carneiro wrote:
>
>> 2009/8/25 Dan Sanduleac <[email protected] <mailto:
>> [email protected]>>
>>
>> Hi,
>>
>> I'm trying to compare different python-C wrapping techniques to
>> see which would be faster and also more suited to game development.
>>
>>
>> If your project does not use multiple inheritance, I may suggest you also
>> try with PyBindGen: http://code.google.com/p/pybindgen/
>>
>> Yes, me being the pybindgen author, I am biased, but still... I am
>> curious to comparisons of pybindgen performance to other python wrapping
>> tools.
>>
>
> That's a strange line of argument. Didn't the original poster ask for
> advice ? It's your turn to do your homework and show why using PyBindGen is
> the better choice, instead of inviting people to use it and report back to
> you whether it was any good.
>
Hm.. but each person knows best the environment they work for. It would be
presumptuous of me to tell him pybindgen is the better choice.
I don't have the full benchmarking setup, but here's how to wrap that
example (attached). I had to add a default Vec3 constructor, since
pybindgen does not like very much classes without default constructors.
You generate the module with:
python vec3-gen.py > vec3module.cc
Compile with something like:
g++ -O2 -fPIC -shared -I /usr/include/python2.6 vec3module.cc vec3.cpp -o
vec3.so
As for the benchmarking stuff, I leave to the original poster.
--
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
import sys
import pybindgen
from pybindgen import ReturnValue, Parameter, Module, CppClass, CppMethod, CppConstructor, FileCodeSink
def my_module_gen(out_file):
mod = Module('vec3')
mod.add_include('"vec3.h"')
Vec3 = mod.add_class('Vec3')
Vec3.add_constructor([Parameter.new('float', 'x'), Parameter.new('float', 'y'), Parameter.new('float', 'z')])
Vec3.add_inplace_numeric_operator('+=')
Vec3.add_inplace_numeric_operator('*=', right='float')
mod.generate(FileCodeSink(out_file))
if __name__ == '__main__':
my_module_gen(sys.stdout)
_______________________________________________
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig