Combining various languages

Started by
10 comments, last by ah_bk88 20 years, 9 months ago
How often are different languages used in the entire game development process? Like can any language be used to write a DLL that can be refered to by any language? This is a confusing question... If I write a DLL in VBasic, can I then refer to it in VC++ etc...? I know there has to be a better way to ask this, but if you get what I''m trying to ask, great, otherwise I''ll try to clarify.
I AM an Army of One... I just have 10,000 other Armies of One to back me up!
Advertisement
Well, with modern videogames just about everything is written in C++ with the occasional scripting language here and there.

In other softwares, like those developed for Windows, you can easily write a .dll with C++ and then put it to use with a program written in VB.

---------------------------------------------------
laziness is the foundation of efficiency
retrospiral.net | llamas! | megatokyo | FreeBSD | gamedev.net | google
laziness is the foundation of efficiency | www.AdrianWalker.info | Adventures in Game Production | @zer0wolf - Twitter
.NET is (largely) language agnostic.
Currently, I''m using C# to develop tools and C++ to make the game engine.

Lot''s of people use to combine C/C++ with ASM to make timecritical modules.

And like the moderator said, .NET has a couple of lanugages to choose from (C++, C#, Java & Visual Baisc), but I don''t think they are there to be combined, more like, you can choose to write .NET apps in your favourite lanugage.
----------------------------------------------Petter Nordlander"There are only 10 kinds of people in the world. They who understand binary and those who do not"
But is it possible...?
I AM an Army of One... I just have 10,000 other Armies of One to back me up!
I''m not for sure, but I think you can write a game in different languages all in one source file, don''t quote me on that. I think it''s the extern linkage specification. The general form of it would be
extern "language" function-prototype 


You see, by default functions are linked as C++ functions, but a linkage specification lets you link a function for a different type of language.

The "language" denotes your desired language. Like say for example:
extern "C" void C_func(); 


This specifies that the function C_func will have C linkage. All, or most, C++ compilers can support both C and C++ linkage but some may ALSO ALLOW LINKAGE TO FORTRAN, PASCAL, OR BASIC. You probably need to check your compiler''s documentation for this and check with someone who has used this.

I''ve only grazed this kind of syntax so I''m not for sure on how to REALLY implement it, someone will know.

Hope that helps
quote:Original post by ah_bk88
But is it possible...?
Yes.

quote:Original post by Xiachunyi
I''m not for sure, but I think you can write a game in different languages all in one source file, don''t quote me on that.
If you don''t want us to quote you on it, either verify that it''s true or just don''t say it!

It''s not true, by the way. The extern <language> specification doesn''t redirect compilers in a source file; they exist to direct the linker on how to locate function bodies in object files or libraries.
quote:Original post by Oluseyi
quote:Original post by ah_bk88
But is it possible...?
Yes.


How?

I AM an Army of One... I just have 10,000 other Armies of One to back me up!
quote:
The extern specification doesn''t redirect compilers in a source file; they exist to direct the linker on how to locate function bodies in object files or libraries.


Care to elucidate for me?
quote:Original post by ah_bk88
How?
Varies by language. If you''re using a combination like C/C++ with Lua/Python or something similar, you have an interop mechanism of sorts. Python, for example, supplies a C header file and static/dynamic library containing functions for instantiating a Python interpreter object in C. You can pass Python scripts to this interpreter and you can pass and extract values with certain restrictions. The Boost library supplies Boost.Python as a method for simplifying interfacing between C++ and Python, allowing Python classes to inherit from C++ classes and so on. Pyrex is another technology for writing Python extension modules and allows for the use of C datatypes right in Python code.

See the Scripting Languages and Game Mods forum for more info on solutions like the above.

If you''re using technologies like .NET, the Common Language Runtime is effectively the glue that holds your various components together. Any code that you write to target the .NET Framework is compiled into MSIL, which allows any other .NET-compatible language to access that code and object properties, derive from classes and so forth.

Alternatively, you could simple create dynamic link libraries (Windows) or shared objects (Unix/Linux) in one language and dlimport the method signatures in the other. It''s common practice to write a Win32 DLL in [Visual] C++ encapsulating all the heavy lifting and then write the user interface in Visual Basic.

quote:Original post by Xiachunyi
quote:The extern specification doesn''t redirect compilers in a source file; they exist to direct the linker on how to locate function bodies in object files or libraries.
Care to elucidate for me?
I''m in a good mood, so what the hell...

extern "C" tells the C++ compiler that the code within the scope of the linkage specification is C code and thus is name mangled differently. Therefore, when generating stubs for the linker it uses a different, standard format which aids the linker in retrieving the code definition from object files or static libraries. There is no other linkage specification in C and C++. What you have instead are calling conventions like pascal and, IIRC, fortran. Because C isn''t as closely tied to the two languages (Pascal and FORTRAN) and has significantly different function call conventions (parameter ordering and whether the calling or called code was responsible for maintaining the stack), C supported interop through this mechanism. extern "C" was created explicitly for C++ code to work with C code because of their inherent similarities.

You can look it up for more technical information.

This topic is closed to new replies.

Advertisement