Sign in to follow this  
Angidmench

How can I add code from one language and add it to another?

Recommended Posts

How can I add code from one language and add it to another language? Is this possible? I want to write some code in C# and use it in another language. I've heard of people using multiple languages on a single file, so I wonder how do I go about learning how to do this?

Share this post


Link to post
Share on other sites
Did you have a language in mind? With C#, you can easily create code that can be utilized by many other CLI based languages.

If you want to use your C# code in a language not on that list it might take a little bit more work, but I'm sure there's a way to do it. It certainly will be heavily language dependent.

Anyway, you'll want to look up information on creating and using a 'class library'

edit: oh, didn't see the bit about using multiple languages in a single file. Well I haven't heard of that. Multiple languages in a single project, maybe, but not in a single file.

Share this post


Link to post
Share on other sites
I don't understand why you would ever need this? All I would have to say is any language can be ported to another language pretty much, so why wouldn't one language be ok? Like why would you ever need multiple languages in a single file?

Share this post


Link to post
Share on other sites
Quote:
Original post by nobodynews
Did you have a language in mind? With C#, you can easily create code that can be utilized by many other CLI based languages.

If you want to use your C# code in a language not on that list it might take a little bit more work, but I'm sure there's a way to do it. It certainly will be heavily language dependent.

Anyway, you'll want to look up information on creating and using a 'class library'

edit: oh, didn't see the bit about using multiple languages in a single file. Well I haven't heard of that. Multiple languages in a single project, maybe, but not in a single file.


Thanks, class library is probably what I need to look up. As for using multiple language in single file, I meant that the EXE would be composed of more than one language. Sorry, I was little misleading about that.

Quote:
Original post by Tenac
I don't understand why you would ever need this? All I would have to say is any language can be ported to another language pretty much, so why wouldn't one language be ok? Like why would you ever need multiple languages in a single file?p

It's because, I'm trying to make a project with another language I just started learning, and barely know the features for it yet. I thought adding classes from other language would be interesting idea to try.. just for fun and learning experience.

Share this post


Link to post
Share on other sites
So, first things first. Your terminology is all whacked out. There are ways in which what you are describing can work; basically, you either take the class/code written in language B and rewrite it to conform to the syntax of language A, or you use interoperability functionalities available when working in the context of language A that allow you to interoperate with code compiled in language B.

The first option is trivial, but doesn't involve actually "using" the code of the other language -- you reuse the algorithm, the action that code would perform, but you're still writing code in your original language.

The second option is nontrivial, sometimes impossible. The exact nature of the steps involved in the second option depend on the languages involved (for example, C has a standard binary interface compiled C code can be called by many other languages because of this). This option is not within the domain of the neophyte, and is not in general all that useful or educational to the beginner.

As such, it seems to me that you are persuing a foolish path. Better instead to focus on learning the language you are trying to learn, rather than to seek out crutches in the form of language interoperability because those crutches likely will not actually do the thing you expect (e.g., they may be broken).

Share this post


Link to post
Share on other sites
You could look into DLL's to write functions and such in one language to be used in another language. As far as having multiple languages in one source file, the only thing I could think of is mixing C, C++, and assembly (using __asm only for 32bit apps though) As far as C# I dont believe so, though it very well could be possible. (Just may be difficult to do)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this