To clarify, my answer "no, that's not how executables work" was in response to your question about whether
compilers bundle interpreters into their output. It's possible to develop a program (P) that accepts a source file as input and produces as output an executable file containing an interpreter, and that source as a resource, and that when the file is executed the interpreter interprets the source. In other words,
1 2 3 4 5 6 7
|
void interpret(const char *);
const char *source = "print \"Hello, World!\n\"\n";
int main(){
interpret(source);
}
|
Personally, I would not consider such a program (P) a compiler, but others may have different opinions.
When big companies make video games with Python (let's say), and use some C++ for parts and another language for parts of the game.. How do they link all of these bits? |
The Python library contains interfaces for a host program to interoperate with a guest script.
They can't have .py files in their game resource folder because users can edit it right.. So how do they store their python files or do they compile python? Do they make their own encrypted file extension that only their interpreter can read? Or the code and interpreter are inside the executable itself. |
There's no single answer to your question. One developer might choose one solution and another might choose another. It depends on what their priorities are. Suffice it to say that all of those are possible solutions (although note that you can't really encrypt the scripts, since the computer needs to be able to execute them at some point. At best you can make it more difficult to find the scripts).
If you could just store any file in .exe why wouldn't you just store everything? |
There are many valid reasons.
* You might want to actually support modding.
* If you support updates, the update procedure for a single monolithic file is much more complex, and you can't update only bits at a time. It's all or nothing.
* Your build procedure becomes more difficult if you have to produce a single file. For one, the amount of parallelism you can add to your build process is inherently limited because that one file has to be written in a specific order.
And so on. Ultimately, having just one file doesn't really solve any problems.
Do they store their code outside the executable? How do they store it? |
Yes, as scripts or as dynamic libraries. For example, the game could unload the audio library, update it, and then reload it.
but since C++ is faster, wouldn't it pay to compile several bits of code separately and then change the bit that needs to be updated. |
But then your code would have to stay very loosely coupled, because different bits may change independently. Open your task manager now. Imagine if every process that's currently running on your computer was instead each running on a separate computer and they were all communicating through a network. Do you think such a system would be faster or slower than your current system?
C++ may be faster, but that doesn't mean that it matters. For example if you have an AI routine that has to run once per second and the Python implementation finishes in 1 millisecond, what would be the point of rewriting it in C++ so it takes 100 microseconds?
Would it make sense to make a program in java or whatever language and use C++ only for computation or whatever parts C++ is faster in? |
Usually Java is fast enough that this is not necessary, but yes, this does make sense sometimes.
Can communication b/w languages be fast enough? |
Passing data accross a foreign function interface (FFI) is generally slow and best to a minimum. You can still do what I said in the previous paragraph, you just have to be a little careful in how you design the interface.