开发者

Any high-level languages that can use c libraries?

开发者 https://www.devze.com 2023-01-02 18:12 出处:网络
I know this question could be in vain, but it\'s just out of curiosity, and I\'m still much a newb^^ Anyways I\'ve been loving python for some time while learning it. My problem is obviously speed iss

I know this question could be in vain, but it's just out of curiosity, and I'm still much a newb^^ Anyways I've been loving python for some time while learning it. My problem is obviously speed issues. I'd like to get into indie game creation, and for the short future, 2d and pygame will work.

But I'd eventually like to branch into the 3d area, and python is really too slow to make anything 3d and professional. So I'm wondering if there has ever been work to create a high-level language able to import and use c libraries? I've looked at Genie and it seems to be able to use certain libraries, but I'm not sure to what extent. Will I be able to use it for openGL programing, or in a c game engine?

I do know some lisp and enjoy it a lot, but there aren't a great many libraries out there for it. Which leads to the problem: I can't stand C syntax, but C has libraries galore that I could need! And game engines like irrlicht.开发者_运维问答 Is there any language that can be used in place of C around C?

Thanks so much guys


Python can call functions in dynamically loaded C libraries (.so in unix, .dll in Windows) using the ctypes module.

There is also cython - a variation of python that compiles to C and can call C libraries directly. You can mix modules written in pure Python and cython.

You may also want to look at the numerous 3D game engines either written specifically for Python or with a python interface. The ones I have heard the most about (but not used) are Blender and Python-Ogre.


Panda3D is an engine which uses Python as it's "game logic" interface. You basically write everything in Python and the Panda3D backend (which I assume is mostly written in C or C++) is responsible for rendering.

Check out the gallery of projects that use Panda3D. It's not going to be AAA the-next-Gears-of-War level graphics, but it's still pretty impressive.


Using swig you can make C imports in various languages: lua, python, php, c# ...

See more info here about supported wrappers.


Python is able to use C libraries via the ctypes module. You'll have to write some Python code to import the C functions, but if the C API is clean and simple you'll have no trouble at all.


You might find these useful:

  • C functions from Python
  • Integrating Python, C and C++


I have been using PyOpenGL, it works great. Swig does its job if you want to call C/C++ libraries from Python.


I'm surprised that no-one has yet stated clearly that C++ is what you are looking for. Like you I have a distaste for C syntax, but that's a poor reason for avoiding C++ if you want to get into 3D gaming. Do you want to dive into 3D gaming, or do you want to sit on the edge of the pool crying that the water is too cold ?

I think you'll also find that C++ plays very well with OpenGL, which is probably not true of a lot of the alternatives that have already been suggested


To some extent, Cython might be what you are looking for. It allows you to use Python as a high level language, but then use C for the parts that need to be optimized.

But, at the end of the day, if you want to do 3D, just learning C or C++ may be the way to go. :-)


There are Python wrappers available for major open source game engines (Ogre, Irrlicht, etc.). Particularly Panda3D ought to have nice bindings.


If you'd like to have a look at .Net platform. You have the following solution:

  1. Use C++/CLI to compile your C/C++ code into .Net assembly, the running time of this part would be as the same as your native C/C++ code.

  2. Use any .Net language (C#, F#, IronPython) to develop high-level stuff using the low level library. For pure number crunching, C#/F# is usually 2-4 times slower than native C code, which is still far faster than Python. For non-number crunching tasks, C#/F# could sometimes match the speed of native code.

0

精彩评论

暂无评论...
验证码 换一张
取 消