HGE and Python (again)
prahaai at gmail.com
Sat Dec 13 07:17:57 CET 2008
Thank you so much for your answer Diez!
I managed to call HGE dll the way you told:
>>> HGE = windll.LoadLibrary("C:/hge181/hge")
But it's not helpful. It would mean that i have to re-create all the
header files from "include" directory in python, and all helper
functions from the "libs" to be able to use hge in the same way as the
So ctypes is not what i need. It's a big step!
I also tried swig, a lot.
A lot, a lot, a lot of examples. Hacking examples and stuff.
And i managed to compile "hge.h" header and call the structs and HGE
main class. I don't seem to be able to acces the "enums", but that's
not a big problem.
How i did that, if anyone wants to know: There are 4 files.
- There is "example.cxx", that includes "hge.h" in the proper C++ way
and defines a HGE* hge=0 just like in the tutorials.
- Then is "hge.h", the original file, with ONE line commented: line
408 with the DLL EXPORT. Ah, and one more thing. I had to delete ALL
"CALL" keywords from HGE class, because if one CALL appears, the swig
compiler flags the line as error. So, for now, no stdcall.
- Then is "example.i", with "#include "hge.h"" and "%include "hge.h"".
Simple as that.
- And then, there is setup.py. "example_module = Extension('_example',
That's it. I compile it all like this:
swig -c++ -python example.i
setup build_ext --inplace
So it's a huge step for me. The compiler i have in my system is
mingw-3.4.5. I don't know if it's good for this. Maybe i should try a
MS compiler instead?
Next things i want to do:
- try to compile the project with a MS compiles. Visual studio 7.1 or
- learn if i can do stdcalls from swig !!! This is the most important.
- try to compile one normal hge tutorial WITHOUT including "hge.lib"
and "hgehelp.lib". All functions defined there can be included just
like normal headers, the source is there and i compiled the libs
myself. I need this step because i don't think i can include lib files
in a swig project.
- try to do all i did in swig, with Cython. It's pretty easy to use
and faster from what i know.
So i must learn to to stdcalls from swig.
Can anyone suggest how to do that?
I mean, i have lines like:
virtual void CALL Release(); // in HGE class.
void CALL HGE_Impl::Release()
//... // In the "c" file.
, where CALL is defined as "#define CALL __stdcall".
I simply can't make this kind of classes so work in swig.
Thank you very much.
More information about the Python-list