mixing programming languages

Started by
2 comments, last by bn45ty 19 years, 1 month ago
Im just wondering what exactly is possible in mixing and what is commonly done. Im asking because I have a game engine finished in c++ using(supporting)DirectX/OpenGL/Win32/SDL(the engine consists of multiple dll's). Now Im wondering wether it would make any sense to convert it to say C# in order to make a c# game, or is there absolutely no issue in writing a c# dll that is loaded by the c++ engine?? What about Longhorn, will my current dll's still hold as good? -CProgrammer
Advertisement
There probably are major issues calling C# DLLs from C++ and vice-versa. but I'm sure there is documentation on how to do it somewhere. If you have nowhere to turn, take a look at this site: The Code Project. It is similar to GameDev.net but is oriented towards Windows apps, MFC, .NET, and C#.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Microsoft's newer compilers have a good deal of cross-compatibility between mutliple languages, allowing you to freely intermix C++, C#, Visual Basic, etcetera.

For the rest of us Microsoft haters/open source junkies/broke students, the options are more limited. Open source CLI compilers/libraries are still comming into maturity.

Even further back than common bytecode targets, however, there has been some compatable languages. There's the obvious C and C++ - C++ can call functions from a C API (and vicea versa, assuming the C++ function isn't mangled (read: extern "C") and takes only builtin types/pointers as arguments).

I've heard combining C++ and Python is also somewhat common - considering there's support for it in the boost library I'm inclined to suspect that whoever/wherever I heard that from was/is correct.

However, these interminglings require a more "hands on" approach. To spit out the quick start example:

Hello WorldFollowing C/C++ tradition, let's start with the "hello, world". A C++ Function:char const* greet(){   return "hello, world";}can be exposed to Python by writing a Boost.Python wrapper:#include <boost/python.hpp>using namespace boost::python;BOOST_PYTHON_MODULE(hello){    def("greet", greet);}That's it. We're done. We can now build this as a shared library. The resulting DLL is now visible to Python. Here's a sample Python session:>>> import hello>>> print hello.greet()hello, world
It's perfectly possible.

In my previous game, we had our engine written in C++, sitting upon COM, and all the editors written in C#.

However, what really makes me angry is not mixed-language environment, but a lack of standard for object-format for C++ compilers (ie I can't use a DLL compiled with Visual C++ in Borland C++Builder, unless that DLL contains C-functions only, which is really annoying!)

This topic is closed to new replies.

Advertisement